Closed biujee closed 6 years ago
Hi Biujee,
The exception is expected. when mediassession.Dispose() is invoked at the end of the call, the speech recognition task gets cancelled. On the last commit we removed the AudioMediaReceived subscription where we get audio buffers sent to the transcription service. You can take a look at the previous commit to have an example of the previous usage. I will update the sample. // subscribe to the audio socket events _audioSocket.AudioMediaReceived += OnAudioMediaReceived;
private void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e)
{
CorrelationId.SetCurrentId(_correlationId);
Log.Verbose(
new CallerInfo(),
LogContext.Media,
"[{0}] [AudioMediaReceivedEventArgs(Data=<{1}>, Length={2}, Timestamp={3}, AudioFormat={4})]",
this.Id,
e.Buffer.Data.ToString(),
e.Buffer.Length,
e.Buffer.Timestamp,
e.Buffer.AudioFormat);
byte[] buffer = new byte[e.Buffer.Length];
Marshal.Copy(e.Buffer.Data, buffer, 0, (int)e.Buffer.Length);
//If the recognize had completed with error/timeout, the underlying stream might have been swapped out on us and disposed.
//so ignore the objectDisposedException
try
{
_recognitionStream.Write(buffer, 0, buffer.Length);
}
catch (ObjectDisposedException)
{
Log.Info(new CallerInfo(), LogContext.Media, $"[{this.Id}]: Write on recognitionStream threw ObjectDisposed");
}
catch (Exception ex)
{
Log.Error(new CallerInfo(), LogContext.Media, $"[{this.Id}]: Caught an exception while processing the audio buffer {ex.ToString()}");
}
finally
{
e.Buffer.Dispose();
}
}
Thank you!
fixed
Hi,
in the HueBot I'm getting an exception by starting speech recognition and there is no inner exception or further information. When I look at the code I'm not sure how the audio stream comes in. The recognition stream will only be set as: _recognitionStream = new SpeechRecognitionPcmStream(16000);
the exception occures at: await _speechClient.RecognizeAsync(new SpeechInput(_recognitionStream, requestMetadata), _recognitionCts.Token);
EventName="MessageEvent" Message="[56f59758-11a8-48d3-971b-464e61b6358a StartSpeechRecognition,MediaSession.cs(254)] [56f59758-11a8-48d3-971b-464e61b6358a:876b4db5-cdba-48c5-b8ab-7e336f503d86]: Speech recognize threw exception System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bing.Speech.AudioReader.d__18.MoveNext()....