process method

void process(
  1. List<int> frame
)

Processes a frame of the incoming audio stream. Upon detection of wake word and completion of follow-on command inference invokes user-defined callbacks.

frame A frame of audio samples. The number of samples per frame can be attained by calling .frameLength. The incoming audio needs to have a sample rate equal to .sample_rate and be 16-bit linearly-encoded. Picovoice operates on single-channel audio.

Implementation

void process(List<int> frame) async {
  if (_porcupine == null || _rhino == null) {
    throw PicovoiceInvalidStateException(
        "Cannot process frame - resources have been released.");
  }

  if (frame.length != frameLength) {
    throw PicovoiceInvalidArgumentException(
        "Picovoice process requires frames of length $frameLength. Received frame of size ${frame.length}.");
  }

  if (!_isWakeWordDetected) {
    final int keywordIndex = await _porcupine!.process(frame);
    if (keywordIndex >= 0) {
      _isWakeWordDetected = true;
      _wakeWordCallback();
    }
  } else {
    RhinoInference inference = await _rhino!.process(frame);
    if (inference.isFinalized) {
      _isWakeWordDetected = false;
      _inferenceCallback(inference);
    }
  }
}