stop method

Future<void> stop()

Closes audio stream and stops Picovoice processing. Throws a PorcupineException if there was a problem stopping audio recording.

Implementation

Future<void> stop() async {
  if (_picovoice == null) {
    return;
  }
  _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}");
    }
  }

  _picovoice?.delete();
  _picovoice = null;
}