我创建了一个振荡器(如下图所示),如MDN所示:

// from : https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.type = 'sine'; // sine wave — other values are 'square', 'sawtooth', 'triangle' and 'custom'
oscillator.frequency.value = 2500; // value in hertz
oscillator.start();


是否有更改音量的方法,就像我更改了频率值一样?

最佳答案

您需要查看修改audioContext和gainNode以进行音量更改。以下链接可能会有所帮助:

https://github.com/mdn/voice-change-o-matic/blob/gh-pages/scripts/app.js

09-20 05:44