到目前为止,我已经找到了一种方法,只能使用MediaRecorder
API记录本地或远程,但是是否可以混合并记录两个流并获得blob?
请注意它的音频蒸汽,我不想在服务器端混音/录音。
我RTCPeerConnection
为pc
。
var local_stream = pc.getLocalStreams()[0];
var remote_stream = pc.getRemoteStreams()[0];
var audioChunks = [];
var rec = new MediaRecorder(local_stream);
rec.ondataavailable = e => {
audioChunks.push(e.data);
if (rec.state == "inactive")
// Play audio using new blob
}
rec.start();
即使我尝试在MediaStream
API中添加多个曲目,但它仍然只提供第一首曲目音频。任何帮助或见解都值得赞赏!
答案 0 :(得分:7)
WebAudio API可以为你做混音。如果要录制数组audioTracks
中的所有音轨:
const ac = new AudioContext();
// WebAudio MediaStream sources only use the first track.
const sources = audioTracks.map(t => ac.createMediaStreamSource(new MediaStream([t])));
// The destination will output one track of mixed audio.
const dest = ac.createMediaStreamDestination();
// Mixing
sources.forEach(s => s.connect(dest));
// Record 10s of mixed audio as an example
const recorder = new MediaRecorder(dest.stream);
recorder.start();
recorder.ondataavailable = e => console.log("Got data", e.data);
recorder.onstop = () => console.log("stopped");
setTimeout(() => recorder.stop(), 10000);