この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

The MediaStreamAudioSourceNode interface is a type of AudioNode which operates as an audio source whose media is received from a MediaStream obtained using the WebRTC or Media Capture and Streams APIs. This media could be from a microphone (through getUserMedia()) or from a remote peer on a WebRTC call (using the RTCPeerConnection's audio tracks).

A MediaStreamAudioSourceNode has no inputs and exactly one output, and is created using the AudioContext.createMediaStreamSource() method.

The MediaStreamAudioSourceNode takes the audio from the first MediaStreamTrack whose kind attribute's value is audio. This is the same as the first track returned by the stream's getAudioTracks() method. There is a complication, however: the order of the tracks is undefined and may vary from browser to browser. For that reason, if you need to select a specific audio track from a stream with multiple audio tracks, you should instead use the MediaStreamTrackAudioSourceNode interface

The number of channels output by the node matches the number of tracks found in the selected audio track.

Number of inputs 0
Number of outputs 1
Channel count defined by the first audio MediaStreamTrack passed to the AudioContext.createMediaStreamSource() method that created it.

Constructor

new MediaStreamAudioSourceNode()
Creates a new MediaStreamAudioSourceNode object instance with the specified options.

Properties

In addition to the following properties, MediaStreamAudioSourceNode inherits the properties of its parent, AudioNode.

mediaStream Read only
The MediaStream used when constructing this MediaStreamAudioSourceNode.

Methods

Inherits methods from its parent, AudioNode.

Example

In this example, we grab a media (audio + video) stream from navigator.getUserMedia, feed the media into a <video> element to play then mute the audio, but then also feed the audio into a MediaStreamAudioSourceNode. Next, we feed this source audio into a low pass BiquadFilterNode (which effectively serves as a bass booster), then a AudioDestinationNode.

The range slider below the <video> element controls the amount of gain given to the lowpass filter — increase the value of the slider to make the audio sound more bass heavy!

Note: You can see this example running live, or view the source.

var pre = document.querySelector('pre');
var video = document.querySelector('video');
var myScript = document.querySelector('script');
var range = document.querySelector('input');

// getUserMedia block - grab stream
// put it into a MediaStreamAudioSourceNode
// also output the visuals into a video element

if (navigator.mediaDevices) {
    console.log('getUserMedia supported.');
    navigator.mediaDevices.getUserMedia ({audio: true, video: true})
    .then(function(stream) {
        video.srcObject = stream;
        video.onloadedmetadata = function(e) {
            video.play();
            video.muted = true;
        };

        // Create a MediaStreamAudioSourceNode
        // Feed the HTMLMediaElement into it
        var audioCtx = new AudioContext();
        var source = audioCtx.createMediaStreamSource(stream);

        // Create a biquadfilter
        var biquadFilter = audioCtx.createBiquadFilter();
        biquadFilter.type = "lowshelf";
        biquadFilter.frequency.value = 1000;
        biquadFilter.gain.value = range.value;

        // connect the AudioBufferSourceNode to the gainNode
        // and the gainNode to the destination, so we can play the
        // music and adjust the volume using the mouse cursor
        source.connect(biquadFilter);
        biquadFilter.connect(audioCtx.destination);

        // Get new mouse pointer coordinates when mouse is moved
        // then set new gain value

        range.oninput = function() {
            biquadFilter.gain.value = range.value;
        }
    })
    .catch(function(err) {
        console.log('The following gUM error occured: ' + err);
    });
} else {
   console.log('getUserMedia not supported on your browser!');
}

// dump script to pre element

pre.innerHTML = myScript.innerHTML;

Note: As a consequence of calling createMediaStreamSource(), audio playback from the media stream will be re-routed into the processing graph of the AudioContext. So playing/pausing the stream can still be done through the media element API and the player controls.

Specification

Specification Status Comment
Web Audio API
The definition of 'MediaStreamAudioSourceNode' in that specification.
Working Draft

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
MediaStreamAudioSourceNodeChrome Full support 23Edge Full support YesFirefox Full support 25IE No support NoOpera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 26Opera Android Full support 14Safari iOS Full support YesSamsung Internet Android Full support Yes
MediaStreamAudioSourceNode() constructorChrome Full support 55
Notes
Full support 55
Notes
Notes Before Chrome 59, the default values were not supported.
Edge ? Firefox Full support 53IE No support NoOpera Full support 42Safari ? 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 53Opera Android Full support 42Safari iOS ? Samsung Internet Android Full support 6.0
mediaStreamChrome Full support 23Edge ? Firefox No support NoIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

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

See also