start method

Future<void> start()

Opens audio input stream and sends audio frames to Picovoice. Throws a PicovoiceException if an instance of Picovoice could not be created.

Implementation

Future<void> start() async {
  if (_picovoice != null) {
    return;
  }

  _picovoice = await Picovoice.create(_accessKey, _keywordPath,
      _wakeWordCallback, _contextPath, _inferenceCallback,
      porcupineSensitivity: _porcupineSensitivity,
      rhinoSensitivity: _rhinoSensitivity,
      porcupineModelPath: _porcupineModelPath,
      rhinoModelPath: _rhinoModelPath,
      endpointDurationSec: _endpointDurationSec,
      requireEndpoint: _requireEndpoint);

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