Skip to content

Commit

Permalink
correction
Browse files Browse the repository at this point in the history
  • Loading branch information
laves committed Aug 3, 2023
1 parent d36b274 commit 03b4e2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Access the singleton instance of `VoiceProcessor`:
```dart
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
VoiceProcessor _voiceProcessor = VoiceProcessor.instance;
VoiceProcessor? _voiceProcessor = VoiceProcessor.instance;
```

Add listeners for audio frames and errors:
Expand All @@ -89,26 +89,30 @@ VoiceProcessorErrorListener errorListener = (VoiceProcessorException error) {
// handle error
}
_voiceProcessor.addFrameListener(frameListener);
_voiceProcessor.addErrorListener(errorListener);
_voiceProcessor?.addFrameListener(frameListener);
_voiceProcessor?.addErrorListener(errorListener);
```

Start audio capture with the desired frame length and audio sample rate:
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;
try {
await _voiceProcessor.start(frameLength, sampleRate);
} on PlatformException catch (ex) {
// handle start error
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();
await _voiceProcessor?.stop();
} on PlatformException catch (ex) {
// handle stop error
}
Expand All @@ -125,11 +129,11 @@ which all listeners will receive once a call to `start()` has been made. To add
VoiceProcessorFrameListener listener1 = (frame) { }
VoiceProcessorFrameListener listener2 = (frame) { }
List<VoiceProcessorFrameListener> listeners = [listener1, listener2];
voiceProcessor.addFrameListeners(listeners);
_voiceProcessor?.addFrameListeners(listeners);
voiceProcessor.removeFrameListeners(listeners);
_voiceProcessor?.removeFrameListeners(listeners);
// or
voiceProcessor.clearFrameListeners();
_voiceProcessor?.clearFrameListeners();
```

## Example
Expand Down
8 changes: 7 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ the `VoiceProcessor`.

## Building

Launch a simulator or connect an Android/iOS device and build with the flutter CLI:
Install dependencies and setup environment:

```console
cd example
flutter pub get
```

Connect a mobile device or launch a simulator. Then build and run the app:
```console
flutter run
```

Expand Down

0 comments on commit 03b4e2d

Please sign in to comment.