Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API" rel="noreferrer">Web Audio API</a> in most browsers now (<a href="http://caniuse.com/#feat=audio-api" rel="noreferrer">excepting IE and Opera Mini</a>).</p> <p>Try out this code:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>// one context per document var context = new (window.AudioContext || window.webkitAudioContext)(); var osc = context.createOscillator(); // instantiate an oscillator osc.type = 'sine'; // this is the default - also square, sawtooth, triangle osc.frequency.value = 440; // Hz osc.connect(context.destination); // connect it to the destination osc.start(); // start the oscillator osc.stop(context.currentTime + 2); // stop 2 seconds after the current time</code></pre> </div> </div> </p> <p>If you want the volume lower, you can do something like this:</p> <pre><code>var context = new webkitAudioContext(); var osc = context.createOscillator(); var vol = context.createGain(); vol.gain.value = 0.1; // from 0 to 1, 1 full volume, 0 is muted osc.connect(vol); // connect osc to vol vol.connect(context.destination); // connect vol to context destination osc.start(context.currentTime + 3); // start it three seconds from now </code></pre> <p>I got most of this from experimenting in chromium while reading the <a href="http://www.w3.org/TR/webaudio/" rel="noreferrer">Web Audio API Working Draft</a>, which I found from @brainjam 's link.</p> <p>I hope that helps. Lastly, it is very helpful to inspect the various objects in the chrome inspector (ctrl-shift-i).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload