简体   繁体   English

是否可以使用 JavaScript 录制浏览器音频元素的播放?

[英]Possibility to record playback of browser audio element using JavaScript?

I am currently working on a simple audio project which uses HTML / JS audio elements to play audio using buttons.我目前正在开发一个简单的音频项目,它使用 HTML / JS 音频元素使用按钮播放音频。

Is it somehow possible to record that audio being played instead of recording the microphone (by using the MediaRecorder API)?是否可以录制正在播放的音频而不是录制麦克风(通过使用 MediaRecorder API)?

After following the steps provided by lawrence-witt , I figured it out.在按照lawrence-witt提供的步骤之后,我想通了。 Here an example for everyone trying to achieve the same:这是每个试图实现相同目标的示例:

const audioContext = new AudioContext();
const destination = audioContext.createMediaStreamDestination();
const mediaRecorder = new MediaRecorder(destination.stream);

// array of 'new Audio()' elements
audioArray.forEach(audio => {
    let stream = audioContext.createMediaStreamSource(audio.captureStream());
    stream.connect(destination);
})

mediaRecorder.start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM