Web/API/MediaStreamAudioDestinationNode

From Get docs

The MediaStreamAudioDestinationNode interface represents an audio destination consisting of a WebRTC MediaStream with a single AudioMediaStreamTrack, which can be used in a similar way to a MediaStream obtained from Navigator.getUserMedia().

It is an AudioNode that acts as an audio destination, created using the AudioContext.createMediaStreamDestination() method.


Number of inputs 1
Number of outputs 0
Channel count 2
Channel count mode "explicit"
Channel count interpretation "speakers"

Constructor

MediaStreamAudioDestinationNode.MediaStreamAudioDestinationNode()
Creates a new MediaStreamAudioDestinationNode object instance.

Properties

Inherits properties from its parent, AudioNode.

MediaStreamAudioDestinationNode.stream
A MediaStream containing a single MediaStreamTrack whose kind is audio and with the same number of channels as the node. You can use this property to get a stream out of the audio graph and feed it into another construct, such as a Media Recorder.

Methods

Inherits methods from its parent, AudioNode.

Example

In the following simple example, we create a MediaStreamAudioDestinationNode, an OscillatorNode and a MediaRecorder (the example will therefore only work in Firefox and Chrome at this time.) The MediaRecorder is set up to record information from the MediaStreamDestinationNode.

When the button is clicked, the oscillator starts, and the MediaRecorder is started. When the button is stopped, the oscillator and MediaRecorder both stop. Stopping the MediaRecorder causes the dataavailable event to fire, and the event data is pushed into the chunks array. After that, the stop event fires, a new blob is made of type opus — which contains the data in the chunks array, and a new window (tab) is then opened that points to a URL created from the blob.

From here, you can play and save the opus file.

<!DOCTYPE html>
<html>
  <head>
    <title>createMediaStreamDestination() demo</title>
  </head>
  <body>
    <h1>createMediaStreamDestination() demo</h1>

    <p>Encoding a pure sine wave to an Opus file </p>
    <button>Make sine wave</button>
    <audio controls></audio>
    <script>
     var b = document.querySelector("button");
     var clicked = false;
     var chunks = [];
     var ac = new AudioContext();
     var osc = ac.createOscillator();
     var dest = ac.createMediaStreamDestination();
     var mediaRecorder = new MediaRecorder(dest.stream);
     osc.connect(dest);

     b.addEventListener("click", function(e) {
       if (!clicked) {
           mediaRecorder.start();
           osc.start(0);
           e.target.innerHTML = "Stop recording";
           clicked = true;
         } else {
           mediaRecorder.stop();
           osc.stop(0);
           e.target.disabled = true;
         }
     });

     mediaRecorder.ondataavailable = function(evt) {
       // push each chunk (blobs) in an array
       chunks.push(evt.data);
     };

     mediaRecorder.onstop = function(evt) {
       // Make blob out of our blobs, and open it.
       var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
       document.querySelector("audio").src = URL.createObjectURL(blob);
     };
    </script>
  </body>
</html>

Note: You can [[../../../../../../mdn.github.io/webaudio-examples/create-media-stream-destination/index|view this example live]], or study the source code, on Github.


Specification

Specification Status Comment
Web Audio APIThe definition of 'MediaStreamAudioDestinationNode' in that specification. Working Draft

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
MediaStreamAudioDestinationNode Chrome

Full support 14

Edge

Full support ≤18

Firefox

Full support 25

IE

No support No

Opera

Full support 15

Safari

Full support 6

WebView Android

Full support Yes

Chrome Android

Full support 18

Firefox Android

Full support 26

Opera Android

Full support 14

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.0

MediaStreamAudioDestinationNode() constructor

Chrome Full support 55

Notes'

Full support 55

Notes'

Notes' Before Chrome 59, the default values were not supported.

Edge

Full support ≤79

Firefox

Full support 53

IE

No support No

Opera

Full support 42

Safari

?

WebView Android Full support 55

Notes'

Full support 55

Notes'

Notes' Before Chrome 59, the default values were not supported.

Chrome Android Full support 55

Notes'

Full support 55

Notes'

Notes' Before Chrome 59, the default values were not supported.

Firefox Android

Full support 53

Opera Android

Full support 42

Safari iOS

?

Samsung Internet Android Full support 6.0

Notes'

Full support 6.0

Notes'

Notes' Before Samsung Internet 7.0, the default values were not supported.

stream Chrome

Full support 14

Edge

Full support ≤18

Firefox

Full support 25

IE

No support No

Opera

Full support 15

Safari

Full support 6

WebView Android

Full support Yes

Chrome Android

Full support 18

Firefox Android

Full support 26

Opera Android

Full support 14

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.'
See implementation notes.


See also