建立
我們首先建立一個音訊上下文,然後建立一個振盪器,這是檢查你的設定是否有效的最簡單方法。 (示例小提琴)
// We can either use the standard AudioContext or the webkitAudioContext (Safari)
var audioContext = (window.AudioContext || window.webkitAudioContext);
// We create a context from which we will create all web audio nodes
var context = new audioContext();
// Create an oscillator and make some noise
var osc = context.createOscillator();
// set a frequecy, in this case 440Hz which is an A note
osc.frequency.value = 440;
// connect the oscillator to the context destination (which routes to your speakers)
osc.connect(context.destination);
// start the sound right away
osc.start(context.currentTime);
// stop the sound in a second
osc.stop(context.currentTime + 1);