Generating sound on the fly with javascript/html5

You can use the Web Audio API in most browsers now (excepting IE and Opera Mini). Try out this 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; // … Read more

Is there a way to use the Web Audio API to sample audio faster than real-time?

There is a really amazing ‘offline’ mode of the Web Audio API that allows you to pre-process an entire file through an audio context and then do something with the result: var context = new webkitOfflineAudioContext(); var source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); source.noteOn(0); context.oncomplete = function(e) { var audioBuffer = e.renderedBuffer; }; context.startRendering(); … Read more

MediaRecorder.stop() doesn’t clear the recording icon in the tab

This is because this recording icon is the one of getUserMedia streaming, not the one of MediaRecorder. When you stop the MediaRecorder, the stream is still active. To stop this gUM stream (or any other MediaStream), you’d call MediaStreamTrack.stop(). stream.getTracks() // get all tracks from the MediaStream .forEach( track => track.stop() ); // stop each … Read more

Why aren’t Safari or Firefox able to process audio data from MediaElementSource?

This answer is quoted almost exactly from my answer to a related question: Firefox 25 and AudioContext createJavaScriptNote not a function Firefox does support MediaElementSource if the media adheres to the Same-Origin Policy, however there is no error produced by Firefox when attempting to use media from a remote origin. The specification is not really … Read more

Using local file for Web Audio API in Javascript

I had the same problem and I found this very simple solution. audio_file.onchange = function(){ var files = this.files; var file = URL.createObjectURL(files[0]); audio_player.src = file; audio_player.play(); }; <input id=”audio_file” type=”file” accept=”audio/*” /> <audio id=”audio_player” /> You can test here: http://jsfiddle.net/Tv8Cm/

Access microphone from a browser – Javascript

Here we capture microphone audio as a Web Audio API event loop buffer using getUserMedia() … time domain and frequency domain snippets of each audio event loop buffer are printed (viewable in browser console just hit key F12 or ctrl+shift+i ) <html><head><meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″> <title>capture microphone audio into buffer</title> <script type=”text/javascript”> var webaudio_tooling_obj = … Read more