Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- navigator.getUserMedia({audio: true},
- function(stream) {
- // create the MediaStreamAudioSourceNode
- var context = new AudioContext();
- var source = context.createMediaStreamSource(stream);
- var recLength = 0,
- recBuffersL = [],
- recBuffersR = [];
- // create a ScriptProcessorNode
- if(!context.createScriptProcessor){
- node = context.createJavaScriptNode(4096, 2, 2);
- } else {
- node = context.createScriptProcessor(4096, 2, 2);
- }
- // listen to the audio data, and record into the buffer
- node.onaudioprocess = function(e){
- recBuffersL.push(e.inputBuffer.getChannelData(0));
- recBuffersR.push(e.inputBuffer.getChannelData(1));
- recLength += e.inputBuffer.getChannelData(0).length;
- }
- // connect the ScriptProcessorNode with the input audio
- source.connect(node);
- // if the ScriptProcessorNode is not connected to an output the "onaudioprocess" event is not triggered in chrome
- node.connect(context.destination);
- },
- function(e) {
- // do something about errors
- });
Add Comment
Please, Sign In to add comment