stachu3478

skrypt_do_dzwieku

May 3rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var AudioContext = window.AudioContext || window.webkitAudioContext;
  2. var context = new AudioContext({ //tworzy główny obiekt do przetwarzania dźwięku
  3.   latencyHint: 'interactive',
  4.   sampleRate: 44100,
  5. });
  6. var source = document.getElementsByTagName("video")[0]; //szuka elementu videło
  7. var node = false;
  8. if(source){
  9.     node = context.createMediaElementSource(source); //przypisuje źródło dźwięku
  10. }else{
  11.     console.log("Nie znaleziono elementu video");
  12. };
  13.  
  14. node.connect(context.destination); //umożliwia odtwarzanie podczas nagrywania
  15.  
  16. var processor = context.createScriptProcessor(4096, 2, 2);
  17. processor.onaudioprocess = function(evt){
  18.     var inputL = evt.inputBuffer.getChannelData(0); //lewy kanal - próbki
  19.     var inputR = evt.inputBuffer.getChannelData(1); //prawy kanal
  20.     for(var n = 0;n < inputL.length;n++){
  21.         if(inputL[n] !== 0 || inputR[n] !== 0){
  22.             console.log(inputL);
  23.             console.log(inputR);
  24.             return true;
  25.         };
  26.     }; // nagrało ciszę
  27.     console.log("Cisza");
  28. };
  29.  
  30. node.connect(processor); //przekierowuje źródło do skryptu przetwarzającego
  31. processor.connect(context.destination); //i zaczyna nagrywanie
  32.  
  33. /*
  34. node.disconnect(processor);
  35. processor.disconnect(context.destination);  //kończy nagrywanie
  36. */
Add Comment
Please, Sign In to add comment