/// <summary> /// Callback from the media platform when raw audio received. This method sends the raw /// audio to the transcriber. The audio is also loopbacked to the user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> 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(); } }
/// <summary> /// Receive audio from subscribed participant. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The audio media received arguments. /// </param> private void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e) { this.GraphLogger.Info($"Received Audio: [VideoMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp})]"); // TBD: Policy Recording bots can record the Audio here e.Buffer.Dispose(); }
/// <summary> /// Receive audio from subscribed participant. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The audio media received arguments.</param> private void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e) { this.GraphLogger.Info($"Received Audio: [AudioMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp})]"); try { if (e.Buffer != null && e.Buffer.UnmixedAudioBuffers != null) { for (int i = 0; i < e.Buffer.UnmixedAudioBuffers.Length; i++) { // MyAudioRecorder.WriteUnmixedAudioBufferToDisk(e.Buffer.UnmixedAudioBuffers[i]); // Transcribe var lTrans = this.GetSTTEngine(e.Buffer.UnmixedAudioBuffers[i].ActiveSpeakerId); if (lTrans != null) { lTrans.Transcribe(e.Buffer.UnmixedAudioBuffers[i]); } } } // await _mediaStream.AppendAudioBuffer(e.Buffer, this.participants); e.Buffer.Dispose(); } catch (Exception ex) { this.GraphLogger.Error(ex); } finally { e.Buffer.Dispose(); } }
/// <summary> /// Save screenshots when we receive audio from the subscribed participant. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The audio media received arguments. /// </param> private void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e) { // leave only logging in here this.logger.Info($"[AudioMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp}, AudioFormat={e.Buffer.AudioFormat}, IsSilence={e.Buffer.IsSilence}, ActiveSpeakers=[{string.Join(", ", e.Buffer.ActiveSpeakers)}])]"); /* TODO: Do something with audio here */ e.Buffer.Dispose(); }
/// <summary> /// Receive audio from subscribed participant. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The audio media received arguments.</param> private async void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e) { this.GraphLogger.Info($"Received Audio: [AudioMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp})]"); try { await _mediaStream.AppendAudioBuffer(e.Buffer, this.participants); e.Buffer.Dispose(); } catch (Exception ex) { this.GraphLogger.Error(ex); } finally { e.Buffer.Dispose(); } }