Path: blob/main/files/en-us/web/api/audiocontext/createmediastreamsource/index.md
6532 views
------{{ APIRef("Web Audio API") }}
The createMediaStreamSource() method of the {{ domxref("AudioContext") }} Interface is used to create a new {{ domxref("MediaStreamAudioSourceNode") }} object, given a media stream (say, from a {{ domxref("MediaDevices.getUserMedia") }} instance), the audio from which can then be played and manipulated.
For more details about media stream audio source nodes, check out the {{ domxref("MediaStreamAudioSourceNode") }} reference page.
Syntax
Parameters
stream: A {{domxref("MediaStream")}} to serve as an audio source to be fed into an audio processing graph for use and manipulation.
Return value
A new {{domxref("MediaStreamAudioSourceNode")}} object representing the audio node whose media is obtained from the specified source stream.
Examples
In this example, we grab a media (audio + video) stream from {{ domxref("navigator.getUserMedia") }}, feed the media into a {{ htmlelement("video") }} element to play then mute the audio, but then also feed the audio into a {{ domxref("MediaStreamAudioSourceNode") }}. Next, we feed this source audio into a low pass {{ domxref("BiquadFilterNode") }} (which effectively serves as a bass booster), then a {{domxref("AudioDestinationNode") }}.
The range slider below the {{ htmlelement("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.
Note: As a consequence of calling
createMediaStreamSource(), audio playback from the media stream will be re-routed into the processing graph of the {{domxref("AudioContext")}}. So playing/pausing the stream can still be done through the media element API and the player controls.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}