到目前为止,我已经找到了一种仅使用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中添加多个音轨,但仍只提供第一音轨音频。任何帮助或见解将不胜感激!
该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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句