https://github.com/picovoice/flutter-voice-processor
Flutter audio recording plugin designed for real-time speech audio processing
https://github.com/picovoice/flutter-voice-processor
android audio audio-processing audio-recorder dart flutter ios java swift
Last synced: 12 months ago
JSON representation
Flutter audio recording plugin designed for real-time speech audio processing
- Host: GitHub
- URL: https://github.com/picovoice/flutter-voice-processor
- Owner: Picovoice
- License: apache-2.0
- Created: 2020-12-02T00:11:50.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T17:57:26.000Z (almost 2 years ago)
- Last Synced: 2024-06-29T01:18:36.212Z (almost 2 years ago)
- Topics: android, audio, audio-processing, audio-recorder, dart, flutter, ios, java, swift
- Language: Dart
- Homepage:
- Size: 14.1 MB
- Stars: 25
- Watchers: 8
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flutter Voice Processor
[](https://github.com/Picovoice/flutter-voice-processor/releases)
[](https://github.com/Picovoice/flutter-voice-processor/)
[](https://pub.dev/packages/flutter_voice_processor)
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
[](https://twitter.com/AiPicovoice)
[](https://www.youtube.com/channel/UCAdi9sTCXLosG1XeqDwLx7w)
The Flutter Voice Processor is an asynchronous audio capture library designed for real-time audio
processing on mobile devices. Given some specifications, the library delivers frames of raw audio
data (16-bit, mono PCM) to the user via listeners.
## Table of Contents
- [Flutter Voice Processor](#flutter-voice-processor)
- [Table of Contents](#table-of-contents)
- [Requirements](#requirements)
- [Compatibility](#compatibility)
- [Installation](#installation)
- [Permissions](#permissions)
- [Usage](#usage)
- [Capturing with Multiple Listeners](#capturing-with-multiple-listeners)
- [Example](#example)
## Requirements
- [Flutter SDK](https://docs.flutter.dev/get-started/install)
- [Android SDK](https://developer.android.com/about/versions/12/setup-sdk) (21+)
- [JDK](https://www.oracle.com/java/technologies/downloads/) (8+)
- [Xcode](https://developer.apple.com/xcode/) (11+)
- [CocoaPods](https://cocoapods.org/)
## Compatibility
- Flutter 1.20.0+
- Android 5.0+ (API 21+)
- iOS 13.0+
## Installation
Flutter Voice Processor is available via [pub.dev](https://pub.dev/packages/flutter_voice_processor).
To import it into your Flutter project, add the following line to your `pubspec.yaml`:
```yaml
dependencies:
flutter_voice_processor: ^
```
## Permissions
To enable recording with the hardware's microphone, you must first ensure that you have enabled the proper permission on both iOS and Android.
On iOS, open the `Info.plist` file and add the following line:
```xml
NSMicrophoneUsageDescription
[Permission explanation]
```
On Android, open the `AndroidManifest.xml` and add the following line:
```xml
```
See our [example app](./example) for how to properly request this permission from your users.
## Usage
Access the singleton instance of `VoiceProcessor`:
```dart
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
VoiceProcessor? _voiceProcessor = VoiceProcessor.instance;
```
Add listeners for audio frames and errors:
```dart
VoiceProcessorFrameListener frameListener = (List frame) {
// use audio
}
VoiceProcessorErrorListener errorListener = (VoiceProcessorException error) {
// handle error
}
_voiceProcessor?.addFrameListener(frameListener);
_voiceProcessor?.addErrorListener(errorListener);
```
Ask for audio record permission and start recording with the desired frame length and audio sample rate:
```dart
final int frameLength = 512;
final int sampleRate = 16000;
if (await _voiceProcessor?.hasRecordAudioPermission() ?? false) {
try {
await _voiceProcessor?.start(frameLength, sampleRate);
} on PlatformException catch (ex) {
// handle start error
}
} else {
// user did not grant permission
}
```
Stop audio capture:
```dart
try {
await _voiceProcessor?.stop();
} on PlatformException catch (ex) {
// handle stop error
}
```
Once audio capture has started successfully, any frame listeners assigned to the `VoiceProcessor` will start receiving audio frames with the given `frameLength` and `sampleRate`.
### Capturing with Multiple Listeners
Any number of listeners can be added to and removed from the `VoiceProcessor` instance. However,
the instance can only record audio with a single audio configuration (`frameLength` and `sampleRate`),
which all listeners will receive once a call to `start()` has been made. To add multiple listeners:
```dart
VoiceProcessorFrameListener listener1 = (frame) { }
VoiceProcessorFrameListener listener2 = (frame) { }
List listeners = [listener1, listener2];
_voiceProcessor?.addFrameListeners(listeners);
_voiceProcessor?.removeFrameListeners(listeners);
// or
_voiceProcessor?.clearFrameListeners();
```
## Example
The [Flutter Voice Processor app](./example) demonstrates how to ask for user permissions and capture output from the `VoiceProcessor`.
## Releases
### v1.1.0 - August 4, 2023
- Numerous API improvements
- Error handling improvements
- Allow for multiple listeners instead of a single callback function
- Upgrades to testing infrastructure and example app
### v1.0.0 - December 8, 2020
- Initial public release.