Web Audio API用於控制音頻,允許您選擇音訊來源。您也可以新增效果;建立音訊視覺化、平移等。
您可以嘗試執行以下程式碼片段來產生聲音−
// 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
以上是使用JavaScript/HTML5即時產生聲音的詳細內容。更多資訊請關注PHP中文網其他相關文章!