stop method
Closes audio stream and stops Picovoice processing.
Throws a PicovoiceException
if there was a problem stopping audio recording.
Implementation
Future<void> stop() async {
if (_picovoice == null) {
throw PicovoiceInvalidStateException(
"Unable to stop - resources have been released.");
}
if (_isListening) {
_voiceProcessor?.removeErrorListener(_errorListener);
_voiceProcessor?.removeFrameListener(_frameListener);
if (_voiceProcessor?.numFrameListeners == 0) {
try {
await _voiceProcessor?.stop();
} on PlatformException catch (e) {
throw PicovoiceRuntimeException(
"Failed to stop audio recording: ${e.message}");
}
}
_isListening = false;
}
await _picovoice?.reset();
}