start method

Future<void> start()

Opens audio input stream and sends audio frames to Picovoice. Throws a PicovoiceException if unable to start.

Implementation

Future<void> start() async {
  if (_picovoice == null) {
    throw PicovoiceInvalidStateException(
        "Unable to start - resources have been released.");
  }

  if (!_isListening) {
    if (await _voiceProcessor?.hasRecordAudioPermission() ?? false) {
      _voiceProcessor?.addFrameListener(_frameListener);
      _voiceProcessor?.addErrorListener(_errorListener);
      try {
        await _voiceProcessor?.start(
            _picovoice!.frameLength!, _picovoice!.sampleRate!);
        _isListening = true;
      } on PlatformException catch (e) {
        throw PicovoiceRuntimeException(
            "Failed to start audio recording: ${e.message}");
      }
    } else {
      throw PicovoiceRuntimeException(
          "User did not give permission to record audio.");
    }
  }
}