2

我正在尝试在 Microsoft.Skype.Bots.Media audioSocket.AudioMediaReceived 上记录传入的缓冲区数据。

根据迄今为止的发现,这可能就像将传入的缓冲区数据保存到磁盘并使用 ffmpeg 之类的工具将缓冲区数据转换为所需的音频格式文件一样。

部分代码片段:

this.audioSocket.AudioMediaReceived += this.OnAudioMediaReceived;

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})]");

            // To Do Recording i.e saving each incoming buffer data and create a audio file after the record ends. 
           e.Buffer.Dispose();
        }

注意:以上代码片段来自合规性记录机器人的 git hub示例

我想出的一种可能的方法是:

 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})]");
            byte[] managedArray = new byte[e.Buffer.Length];
            var handler = e.Buffer.Data;
            int start = 0;
            int length = (int)e.Buffer.Length;
            Marshal.Copy(handler, managedArray, start, length);
            var path = @"D:\files";
            var filePath = Path.Combine(path, "test.wav");
            File.WriteAllBytes(filePath, managedArray);

            // TBD: Compliance Recording bots can record the Audio here
            e.Buffer.Dispose();
        }

但问题是,只要呼叫/录音继续,音频媒体缓冲区数据就会继续来(流),并且此解决方案不起作用。

任何帮助,将不胜感激。

4

0 回答 0