Audio Streamer

Streaming of Pulse-code modulation (PCM) audio from Android and iOS with a customizable sampling rate.


Using this plugin needs permission to access the microphone. Requesting this permission is NOT part of the plugin, but should be handled by the app. However, for the app to be able to access the microphone, the app need to have the following permission on Android and iOS.

On Android add the audio recording permission to AndroidManifest.xml.

<uses-permission android:name="android.permission.RECORD_AUDIO" />

On iOS enable the following using XCode:

  • Capabilities > Background Modes > Audio, AirPlay and Picture in Picture
  • In the Runner Xcode project edit the Info.plist file. Add an entry for 'Privacy - Microphone Usage Description'

If editing the Info.plist file manually, the entries needed are:

<string>YOUR DESCRIPTION</string>

Edit the Podfile to include the permission for the microphone:

post_install do |installer|
  installer.pods_project.targets.each do |target|

    target.build_configurations.each do |config|
      # for more infomation:
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [

Using the plugin

The plugin works as a singleton and provide a simple audioStream to listen to.

  (List<double> buffer) {
    print('Max amp: ${buffer.reduce(max)}');
    print('Min amp: ${buffer.reduce(min)}');
  onError: (Object error) {
  cancelOnError: true,

The sampling rate can be set and read using the samplingRate and actualSampleRate properties.

// Set the sampling rate. Must be done BEFORE listening to the audioStream.
AudioStreamer().sampleRate = 22100;

// Get the real sampling rate - may be different from the requested sampling rate.
int sampleRate = await AudioStreamer().actualSampleRate;


See the file example/lib/main.dart for an example app using the plugin. This app also illustrates how to ask for permission to access the microphone. Note that on iOS the sample rate will not necessarily change, as there is only the option to set a preferred one.