javascripthtml5-audiomediarecorder-api

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.

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


Solution

  • 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();