在视频通话期间将音频添加到传入流中以记录通话双方的语音 [英] Adding audio to an incoming stream during video call to record voice of both parties in a call

查看:52
本文介绍了在视频通话期间将音频添加到传入流中以记录通话双方的语音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用 peer js 来发起视频通话的应用程序.我正在使用 mediarecorder Api 来记录来自呼叫者的传入流.但是,我需要将通话中呼叫者和接收者的音频添加到录音中,并且视频应该仅是呼叫者(传入流).

I have created an app using peer js to initiate video calls. I am using mediarecorder Api to record the incoming stream from caller. However, I need to add audio of both the caller and receiver in the call to the recording, and video should be of only the caller(incoming stream).

我已经尝试过 https://github.com/muaz-khan/MultiStreamsMixer 这个.但是,在录制它时,我通过 vlc 得到了一个无法读取的文件.

I have tried https://github.com/muaz-khan/MultiStreamsMixer this. However, on recording it I get an unreadable file by vlc.

我也尝试将本地音轨添加到录制流中,但这不会将 2 个音轨合并为一个,并且只录制传入流的音频.

I have also tried adding the local audio track to the recording stream, but that doesn't merge the 2 audio tracks into one and only the incomingstream's audio is recorded.

推荐答案

我能够通过使用 Web Audio API 来做到这一点.我从两个流中获取音轨,并使用音频上下文将它们合并为一个.

I was able to do this by using Web Audio API. I fetched the audio tracks from both the streams and joined them into one using audio context.

var OutgoingAudioMediaStream = new MediaStream();
OutgoingAudioMediaStream.addTrack(OutgoingStream.getAudioTracks()[0]);

var IncomingAudioMediaStream = new MediaStream();
IncomingAudioMediaStream.addTrack(IncomingStream.getAudioTracks()[0]);

const audioContext = new AudioContext();

audioIn_01 = audioContext.createMediaStreamSource(OutgoingAudioMediaStream);
audioIn_02 = audioContext.createMediaStreamSource(IncomingAudioMediaStream);

dest = audioContext.createMediaStreamDestination();

audioIn_01.connect(dest);
audioIn_02.connect(dest);

dest.stream.addTrack(IncomingStream.getVideoTracks()[0]);
var RecordingStream = dest.stream;

效果很好.

这篇关于在视频通话期间将音频添加到传入流中以记录通话双方的语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆