audio_streamer 1.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

audio_streamer #

Streaming of PCM audio from Android and iOS with a sample rate of 44,100 Hz

Permissions #

On Android you need to add a permission to AndroidManifest.xml:

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

On iOS enable the following:

  • 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'

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

<key>NSMicrophoneUsageDescription</key>
<string>YOUR DESCRIPTION</string>
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Example Usage #

See the file example/lib/main.dart for a fully fledged example app using the plugin.

  AudioStreamer _streamer = AudioStreamer();
  bool _isRecording = false;
  List<double> _audio = [];
  
  void onAudio(List<double> buffer) {
    _audio.addAll(buffer);
    double secondsRecorded = _audio.length.toDouble() / _streamer.sampleRate.toDouble();
    print('$secondsRecorded seconds recorded.');
  }

  void start() async {
    try {
      _streamer.start(onAudio);
      setState(() {
        _isRecording = true;
      });
    } catch (error) {
      print(error);
    }
  }

  void stop() async {
    bool stopped = await _streamer.stop();
    setState(() {
      _isRecording = stopped;
    });
  }

1.1.6 #

  • Upgrade to permission_handler v. 5.

1.1.5 #

  • Added a getter for the sample rate field.

1.1.0 #

  • Able to stream audio data on Android as well
  • The plugin will now record as soon as the permission dialog ends.

1.0.0 #

  • Able to stream audio data on iOS.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:audio_streamer/audio_streamer.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  AudioStreamer _streamer = AudioStreamer();
  bool _isRecording = false;
  List<double> _audio = [];

  @override
  void initState() {
    super.initState();
  }

  void onAudio(List<double> buffer) {
    _audio.addAll(buffer);
    double secondsRecorded = _audio.length.toDouble() / _streamer.sampleRate.toDouble();
    print('$secondsRecorded seconds recorded.');
  }

  void start() async {
    try {
      _streamer.start(onAudio);
      setState(() {
        _isRecording = true;
      });
    } catch (error) {
      print(error);
    }
  }

  void stop() async {
    bool stopped = await _streamer.stop();
    setState(() {
      _isRecording = stopped;
    });
  }

  List<Widget> getContent() => <Widget>[
        Container(
            margin: EdgeInsets.all(25),
            child: Column(children: [
              Container(
                child: Text(_isRecording ? "Mic: ON" : "Mic: OFF",
                    style: TextStyle(fontSize: 25, color: Colors.blue)),
                margin: EdgeInsets.only(top: 20),
              )
            ])),
      ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: getContent())),
        floatingActionButton: FloatingActionButton(
            backgroundColor: _isRecording ? Colors.red : Colors.green,
            onPressed: _isRecording ? stop : start,
            child: _isRecording ? Icon(Icons.stop) : Icon(Icons.mic)),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  audio_streamer: ^1.1.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:audio_streamer/audio_streamer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
79
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:audio_streamer/audio_streamer.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:audio_streamer/audio_streamer.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:audio_streamer/audio_streamer.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:audio_streamer/audio_streamer.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • audio_streamer that is a package requiring null.

Health suggestions

Fix lib/audio_streamer.dart. (-1 points)

Analysis of lib/audio_streamer.dart reported 2 hints:

line 4 col 8: Duplicate import.

line 6 col 1: Prefer using /// for doc comments.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
permission_handler ^5.0.0 5.0.1+1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
permission_handler_platform_interface 2.0.1
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test