AudioContext.createMediaStreamTrackSource() - Web APIs 编辑

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

SpecificationStatusComment
Web Audio API
The definition of 'createMediaStreamTrackSource()' in that specification.
Working Draft

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:114 次

字数:5146

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文