Skip to content

Instantly share code, notes, and snippets.

@hpcslag
Created December 26, 2014 14:55
Show Gist options
  • Save hpcslag/60e8c09912cfe95ba0c0 to your computer and use it in GitHub Desktop.
Save hpcslag/60e8c09912cfe95ba0c0 to your computer and use it in GitHub Desktop.
Need use localhost, don't use file:///
// success callback when requesting audio input stream
function gotStream(stream) {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var analyser = audioContext.createAnalyser();//x
// Create an AudioNode from the stream.
var mediaStreamSource = audioContext.createMediaStreamSource( stream );
// Connect it to the destination to hear yourself (or any other node for processing!)
mediaStreamSource.connect( audioContext.destination );
analyser.connect(audioContext.destination);
}
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getUserMedia( {audio:true}, gotStream, function(err){ console.log("Error getting audio stream!"); });
/*
navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||navigator.msGetUserMedia);
var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true}, function(stream) {
aCtx = new webkitAudioContext();
analyser = aCtx.createAnalyser();
microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(analyser);
analyser.connect(aCtx.destination);
}, function (){console.warn("Error getting audio stream from getUserMedia")});
};*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment