/// <summary> /// Stops recording audio. /// </summary> /// <param name="continueProcessing"><c>true</c> (default) to finish recording and raise the <see cref="AudioInputReceived"/> event. /// Use <c>false</c> here to stop recording but do nothing further (from an error state, etc.).</param> public async Task StopRecording(bool continueProcessing = true) { audioStream.Flush(); // allow the stream to send any remaining data audioStream.OnBroadcast -= AudioStream_OnBroadcast; try { await audioStream.Stop(); // WaveRecorder will be stopped as result of stream stopping } catch (Exception ex) { Debug.WriteLine("Error in StopRecording: {0}", ex); } OnRecordingStopped(); var returnedFilePath = GetAudioFilePath(); // complete the recording Task for anthing waiting on this recordTask.TrySetResult(returnedFilePath); if (continueProcessing) { Debug.WriteLine($"AudioRecorderService.StopRecording(): Recording stopped, raising AudioInputReceived event; audioDetected == {audioDetected}; filePath == {returnedFilePath}"); AudioInputReceived?.Invoke(this, returnedFilePath); } }
/// <summary> /// Stops recording audio. /// </summary> /// <param name="continueProcessing"><c>true</c> (default) to finish recording and raise the <see cref="AudioInputReceived"/> event. /// Use <c>false</c> here to stop recording but do nothing further (from an error state, etc.).</param> public async Task StopRecording(bool continueProcessing = true) { audioStream.OnBroadcast -= AudioStream_OnBroadcast; try { recorder.StopRecorder(); await audioStream.Stop(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error in StopRecording: {0}", ex.Message); } if (continueProcessing) { System.Diagnostics.Debug.WriteLine("AudioRecorderService.StopRecording(): Recording stopped, raising AudioInputReceived event"); AudioInputReceived?.Invoke(this, audioDetected ? GetFilename() : null); } }