We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS


GainNode 接口表示音量变更。它是一个 AudioNode 音频处理模块,在输出前使用给定 增益 应用到输入。一个 GainNode 总是只有一个输入和一个输出,都通过同样数量的声道。

增益是一个无单位量,会对所有输入声道的音频进行相应的增加。当对 GainNode 进行修改时,新的增益会通过 de-zippering 算法进行应用,以防止出现“咔嗒”的奇怪声响。


The GainNode is increasing the gain of the output.

Number of inputs 1
Number of outputs 1
Channel count mode "max"
Channel count 2 (not used in the default count mode)
Channel interpretation "speakers"


继承自父级, AudioNode.

GainNode.gain 只读
一个a-rate AudioParam ,表示可利用的增益量.


没有具体的方法; 继承自父级, AudioNode.


The following example shows basic usage of an AudioContext to create a GainNode, which is then used to mute and unmute the audio when a Mute button is clicked by changing the gain property value.

The below snippet wouldn't work as is — for a complete working example, check out our Voice-change-O-matic demo (view source.)

  <a class="mute">Mute button</a>
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var gainNode = audioCtx.createGain();
var mute = document.querySelector('.mute');
var source;

if (navigator.mediaDevices.getUserMedia) {
 navigator.mediaDevices.getUserMedia (
   // constraints - only audio needed for this app
     audio: true

   // Success callback
   function(stream) {
     source = audioCtx.createMediaStreamSource(stream);


   // Error callback
   function(err) {
     console.log('The following gUM error occured: ' + err);
} else {
   console.log('getUserMedia not supported on your browser!');



mute.onclick = voiceMute;

function voiceMute() {
  if(mute.id == "") {
    gainNode.gain.setValueAtTime(0, audioCtx.currentTime);
    mute.id = "activated";
    mute.innerHTML = "Unmute";
  } else {
    gainNode.gain.setValueAtTime(1, audioCtx.currentTime);
    mute.id = "";
    mute.innerHTML = "Mute";


Specification Status Comment
Web Audio API
Working Draft  


We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 10.0webkit 25.0 (25.0)  未实现 15.0webkit
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? 26.0 1.2 ? ? ? 33.0



此页面的贡献者: huangxok, SoAanyip
最后编辑者: huangxok,