startListening method

Future<bool> startListening({
  1. dynamic processSamples(
    1. dynamic
    )?,
  2. dynamic onError(
    1. dynamic
    )?,
})

Attempts to initialize the audio stream and begins listening to the mic. It can return false if an error is encountered or if the permission to record audio has not been granted

Implementation

Future<bool> startListening(
    {Function(dynamic)? processSamples, Function(dynamic)? onError}) async {
  final initialized = await _augnitoMicStream.initialize(_sampleRate);
  if (!initialized) {
    _logger?.log(this,
        "Unable to initialize. Check that recording permissions are granted.");
    return false;
  }
  final startedRecording = await _augnitoMicStream.startRecording();
  if (!startedRecording) {
    _logger?.log(this, "unable to start recording.");
    return false;
  }
  _audioStream = _augnitoMicStream.audioStream.listen((data) {
    if (processSamples != null) {
      processSamples(data);
    }
  }, onError: (error) {
    if (onError != null) {
      onError(error);
    }
  });
  return true;
}