Possibility to record playback of browser audio element using JavaScript?

567 views Asked by At

I am currently working on a simple audio project which uses HTML / JS audio elements to play audio using buttons.

Is it somehow possible to record that audio being played instead of recording the microphone (by using the MediaRecorder API)?

1

There are 1 answers

0
mrvnklm On BEST ANSWER

After following the steps provided by lawrence-witt, I figured it out. 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();