willow_flutter_sound 1.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

flutter_sound #

pub version

This plugin provides simple recorder and player functionalities for both `android` and `ios` platforms. This only supports default file extension for each platform. This plugin handles file from remote url. This plugin can handle playback stream from native (To sync exact time with bridging).

Free Read #

Medium Blog

Getting Started #

For help getting started with Flutter, view our online documentation.

Install #

Add flutter_sound as a dependency in pubspec.yaml For help on adding as a dependency, view the documentation.

Post Installation #

On iOS you need to add a usage description to info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This sample uses the microphone to record your speech and convert it to text.</string>
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
</array>

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

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

Methods #

FuncParamReturnDescription
setSubscriptionDurationdouble secString messageSet subscription timer in seconds. Default is 0.01 if not using this method.
startRecorderString uri, int sampleRate, int numChannelsString uriStart recording. This will return uri used.
stopRecorderString messageStop recording.
startPlayerString uriString messageStart playing.
stopPlayerString messageStop playing.
pausePlayerString messagePause playing.
resumePlayerString messageResume playing.
seekToPlayerint milliSecs position to goToString messageSeek audio to selected position in seconds. Parameter should be less than audio duration to correctly placed.

Subscriptions #

SubscriptionReturnDescription
onRecorderStateChanged<RecordStatus>Able to listen to subscription when recorder starts.
onPlayerStateChanged<PlayStatus>Able to listen to subscription when player starts.

Default uri path #

When uri path is not set during the function call in startRecorder or startPlayer, they are saved in below path depending on the platform.

  • Default path for android
    • sdcard/sound.mp4.
  • Default path for ios
    • sound.m4a.

Usage #

Creating instance. #

FlutterSound flutterSound = new FlutterSound();

Starting recorder with listener. #

String path = await flutterSound.startRecorder(null);
print('startRecorder: $path');

_recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) {
  DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
  String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
});

Stop recorder #

String result = await flutterSound.stopRecorder();
print('stopRecorder: $result');

if (_recorderSubscription != null) {
	_recorderSubscription.cancel();
	_recorderSubscription = null;
}

Start player #

String path = await flutterSound.startPlayer(null);
print('startPlayer: $path');

_playerSubscription = flutterSound.onPlayerStateChanged.listen((e) {
	if (e != null) {
		DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
		String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
		this.setState(() {
			this._isPlaying = true;
			this._playerTxt = txt.substring(0, 8);
		});
	}
});

Stop player #

String result = await flutterSound.stopPlayer();
print('stopPlayer: $result');
if (_playerSubscription != null) {
	_playerSubscription.cancel();
	_playerSubscription = null;
}

Pause player #

String result = await flutterSound.pausePlayer();

Resume player #

String result = await flutterSound.resumePlayer();

Seek player #

String result = await flutterSound.seekToPlayer(miliSecs);

Setting subscription duration (Optional). 0.01 is default value when not set. #

/// 0.01 is default
flutterSound.setSubscriptionDuration(0.01);

Setting volume. #

/// 1.0 is default
/// Currently, volume can be changed when player is running. Try manage this right after player starts.
String path = await flutterSound.startPlayer(null);
await flutterSound.setVolume(0.1);

Using the amplitude meter #

The amplitude meter allows displaying a basic representation of the input sound. When enabled, it returns values ranging 0-120dB.

//// By default this option is disabled, you can enable it by calling
setDbLevelEnabled(true);
//// You can tweak the frequency of updates by calling this function (unit is seconds)
updateDbPeakProgress(0.8);
//// You need to subscribe in order to receive the value updates
_dbPeakSubscription = flutterSound.onRecorderDbPeakChanged.listen((value) {
  setState(() {
    this._dbLevel = value;
  });
});

TODO #

  • [ ] Seeking example in Exmaple project
  • [x] Volume Control
  • [x] Sync timing for recorder callback handler

Help Maintenance #

I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it. <br/>Buy Me A Coffee

1.3.+ #

  • Support db/meter #41

1.2.+ #

  • Fixed sound distorting when playing recorded audio again. Issue #14.
  • Fixed seekToPlayer for android. Issue #10.
  • Expose recorder sampleRate and numChannel.
  • Do not append tmp when filePath provided in ios.
  • Resolve regression issue in 1.2.3 which caused in 1.2.2.
  • Reduce the size of audio file in 1.2.4. Related #26.
  • Fixed recording issue in android in 1.2.5.
  • Changed seekToPlayer to place exact secs instead adding it.
  • Fix file URI for recording and playing in iOS.

1.1.+ #

  • Released 1.1.0 with beautiful logo from mansa.
  • Improved readme.
  • Resolve #7.
  • Fixed missing break in switch statement.

1.0.9 #

  • Reimport intl which is needed to format date in Dart.

1.0.8 #

  • Implemented setVolume method.
  • Specific error messages given in android.
  • Manage ios player thread when audio is not loaded.

1.0.7 #

  • Safer handling of progressUpdate in ios when audio is invalid.

1.0.6 #

  • Fixed bug in platform specific code.

1.0.5 #

  • Fixed pug in seekToPlayer in ios.

1.0.3 #

  • Added license.

1.0.0 #

  • Released preview version for audio recorder and player.

example/README.md

flutter_sound_example #

This is not a playlist audio module and this library provides simple recorder and player functionalities for both android and ios platforms. This only supports default file extension for each platform. This module can also handle file from url.

Getting Started #

For help getting started with Flutter, view our online documentation.

Install #

Add flutter_sound as a dependency in pubspec.yaml For help on adding as a dependency, view the documentation.

Post Installation #

On iOS you need to add a usage description to info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This sample uses the microphone to record your speech and convert it to text.</string>
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
</array>

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

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

Use this package as a library

1. Depend on it

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


dependencies:
  willow_flutter_sound: ^1.3.2

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:willow_flutter_sound/willow_flutter_sound.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

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

Analysis of lib/willow_flutter_sound.dart reported 2 hints:

line 35 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

line 55 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8