Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. navigator.getUserMedia({audio: true},
  2. function(stream) {
  3. // create the MediaStreamAudioSourceNode
  4. var context = new AudioContext();
  5. var source = context.createMediaStreamSource(stream);
  6. var recLength = 0,
  7. recBuffersL = [],
  8. recBuffersR = [];
  9.  
  10. // create a ScriptProcessorNode
  11. if(!context.createScriptProcessor){
  12. node = context.createJavaScriptNode(4096, 2, 2);
  13. } else {
  14. node = context.createScriptProcessor(4096, 2, 2);
  15. }
  16.  
  17. // listen to the audio data, and record into the buffer
  18. node.onaudioprocess = function(e){
  19. recBuffersL.push(e.inputBuffer.getChannelData(0));
  20. recBuffersR.push(e.inputBuffer.getChannelData(1));
  21. recLength += e.inputBuffer.getChannelData(0).length;
  22. }
  23.  
  24. // connect the ScriptProcessorNode with the input audio
  25. source.connect(node);
  26. // if the ScriptProcessorNode is not connected to an output the "onaudioprocess" event is not triggered in chrome
  27. node.connect(context.destination);
  28. },
  29. function(e) {
  30. // do something about errors
  31. });
Add Comment
Please, Sign In to add comment