process method

Future<void> process()

Starts audio recording and processing with the Rhino engine until a inference result is sent via the inferenceCallback Throws a RhinoException if there was a problem starting audio recording.

Implementation

Future<void> process() async {
  if (_isListening) {
    return;
  }

  if (_rhino == null || _voiceProcessor == null) {
    throw RhinoInvalidStateException(
        "Cannot start Rhino - resources have already been released");
  }

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

  _isListening = true;
}