将两个音轨合并为一个音轨
Merge two audio tracks into one track
我在将两个音轨合并为一个时遇到问题,以便将整个合并后的音频添加到视频轨道。
this.promises = [navigator.mediaDevices.getUserMedia({ audio: true, video: true })];
if (navigator['getDisplayMedia']) {
this.promises.push(navigator['getDisplayMedia'](this.streamConstraints));
}
else if (navigator.mediaDevices['getDisplayMedia']) {
this.promises.push(navigator.mediaDevices['getDisplayMedia'](this.streamConstraints));
}
else {
this.promises.push(navigator.mediaDevices.getUserMedia({ video: { mediaSource: 'screen' } as any }));
}
Promise.all(this.promises)
.then((streams) => {
// so here is the microphone audio and webcam video
const avTracks = streams[0].getTracks();
// here is the screen video and audio
const screenRecordTracks = streams[1].getTracks();
const firstAudioTrack = new MediaStream(avTracks).getAudioTracks();
const secondAudioTrack= new MediaStream(screenRecordTracks ).getAudioTracks();
// so here I want to merge these two audio tracks, and them to add this final track to the first video track like so..
const wholeRecord = new MediaStream(avTracks).getVideoTracks(); + the merged audio track
如何将它们合并到一首曲目中,有人可以帮助我吗?
我可以通过使用网络音频来做到这一点 API。我从两个流中获取了音轨,并使用音频上下文将它们合并为一个。
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);
var FinalStream = dest.stream;
效果很好。
我在将两个音轨合并为一个时遇到问题,以便将整个合并后的音频添加到视频轨道。
this.promises = [navigator.mediaDevices.getUserMedia({ audio: true, video: true })];
if (navigator['getDisplayMedia']) {
this.promises.push(navigator['getDisplayMedia'](this.streamConstraints));
}
else if (navigator.mediaDevices['getDisplayMedia']) {
this.promises.push(navigator.mediaDevices['getDisplayMedia'](this.streamConstraints));
}
else {
this.promises.push(navigator.mediaDevices.getUserMedia({ video: { mediaSource: 'screen' } as any }));
}
Promise.all(this.promises)
.then((streams) => {
// so here is the microphone audio and webcam video
const avTracks = streams[0].getTracks();
// here is the screen video and audio
const screenRecordTracks = streams[1].getTracks();
const firstAudioTrack = new MediaStream(avTracks).getAudioTracks();
const secondAudioTrack= new MediaStream(screenRecordTracks ).getAudioTracks();
// so here I want to merge these two audio tracks, and them to add this final track to the first video track like so..
const wholeRecord = new MediaStream(avTracks).getVideoTracks(); + the merged audio track
如何将它们合并到一首曲目中,有人可以帮助我吗?
我可以通过使用网络音频来做到这一点 API。我从两个流中获取了音轨,并使用音频上下文将它们合并为一个。
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);
var FinalStream = dest.stream;
效果很好。