Web Audio API用于控制音頻,允許您選擇音頻源。您還可以添加效果;創(chuàng)建音頻可視化、平移等。
示例
您可以嘗試運(yùn)行以下代碼片段來生成聲音?
// use one context per document. Here we are creating one context for one document. You can create for other documents also var context = new (window.AudioContext || window.webkitAudioContext)(); // oscillator var os = context.createOscillator(); os.type = 'sine'; // sine is the default. So you can also use square, saw tooth, triangle os.frequency.value = 500; // setting the frequency Hz os.connect(context.destination); // connecting to the destination // starting the oscillator os.start(); os.stop(context.currentTime + 5); // stop 5 seconds after the current time
登錄后復(fù)制
以上就是使用JavaScript/HTML5實(shí)時(shí)生成聲音的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!