AudioContext.createMediaStreamTrackSource()

Наши волонтёры ещё не перевели данную статью на Русский. Присоединяйтесь к нам и помогите сделать эту работу!
Вы можете также прочитать эту статью на English (US).

Draft
This page is not complete.

The createMediaStreamTrackSource() method of the AudioContext interface creates and returns a MediaStreamTrackAudioSourceNode which represents an audio source whose data comes from the specified MediaStreamTrack.

This differs from createMediaStreamSource(), which creates a MediaStreamAudioSourceNode whose audio comes from the audio track in a specified MediaStream whose id is first, lexicographically (alphabetically).

Syntax

var audioCtx = new AudioContext();
var track = audioCtx.createMediaStreamTrackSource(track);

Parameters

track
The MediaStreamTrack to use as the source of all audio data for the new node.

Return value

A MediaStreamTrackAudioSourceNode object which acts as a source for audio data found in the specified audio track.

Example

In this example, getUserMedia() is used to request access to the user's microphone. Once that access is attained, an audio context is established and a MediaStreamTrackAudioSourceNode is created using createMediaStreamTrackSource(), taking its audio from the first audio track in the stream returned by getUserMedia().

Then a BiquadFilterNode is created using createBiquadFilter(), and it's configured as desired to perform a lowshelf filter on the audio coming from the source. The output from the microphone is then routed into the new biquad filter, and the filter's output is in turn routed to the audio context's destination.

navigator.mediaDevices.getUserMedia ({audio: true, video: false})
.then(function(stream) {
  audio.srcObject = stream;
  audio.onloadedmetadata = function(e) {
    audio.play();
    audio.muted = true;
  };

  let audioCtx = new AudioContext();
  let source = audioCtx.createMediaStreamSource(stream);

  let biquadFilter = audioCtx.createBiquadFilter();
  biquadFilter.type = "lowshelf";
  biquadFilter.frequency.value = 3000;
  biquadFilter.gain.value = 20;

  source.connect(biquadFilter);
  biquadFilter.connect(audioCtx.destination);
})
.catch(function(err) {
  // Handle getUserMedia() error
});

Specifications

Specification Status Comment
Web Audio API
The definition of 'createMediaStreamTrackSource()' 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
createMediaStreamTrackSourceChrome No support NoEdge No support NoFirefox Full support 68
Notes
Full support 68
Notes
Notes Firefox 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android Full support 68
Notes
Full support 68
Notes
Notes Firefox 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

See also

Метки документа и участники

Внесли вклад в эту страницу: Sheppy, mdnwebdocs-bot, fscholz, chrisdavidmills
Обновлялась последний раз: Sheppy,