Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var AudioContext = window.AudioContext || window.webkitAudioContext;
- var context = new AudioContext({ //tworzy główny obiekt do przetwarzania dźwięku
- latencyHint: 'interactive',
- sampleRate: 44100,
- });
- var source = document.getElementsByTagName("video")[0]; //szuka elementu videło
- var node = false;
- if(source){
- node = context.createMediaElementSource(source); //przypisuje źródło dźwięku
- }else{
- console.log("Nie znaleziono elementu video");
- };
- node.connect(context.destination); //umożliwia odtwarzanie podczas nagrywania
- var processor = context.createScriptProcessor(4096, 2, 2);
- processor.onaudioprocess = function(evt){
- var inputL = evt.inputBuffer.getChannelData(0); //lewy kanal - próbki
- var inputR = evt.inputBuffer.getChannelData(1); //prawy kanal
- for(var n = 0;n < inputL.length;n++){
- if(inputL[n] !== 0 || inputR[n] !== 0){
- console.log(inputL);
- console.log(inputR);
- return true;
- };
- }; // nagrało ciszę
- console.log("Cisza");
- };
- node.connect(processor); //przekierowuje źródło do skryptu przetwarzającego
- processor.connect(context.destination); //i zaczyna nagrywanie
- /*
- node.disconnect(processor);
- processor.disconnect(context.destination); //kończy nagrywanie
- */
Add Comment
Please, Sign In to add comment