2014-11-21 4 views
0

을 통해 오디오 파일에서 데시벨 수준을 얻으려고 노력 :내가 여기에 정보에서 찾아 봤는데 자바 스크립트

Is there a way get something like decibel levels from an audio file and transform that information into a json array?

을하지만 난 여기에 JSBin를 실행하려고하면

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset=utf-8 /> 
    <title>Get Audio Data</title> 
    <link rel="stylesheet" type="text/css" href="index.css"> 
    <script type="text/javascript" src="music.js"></script> 
    </head> 
    <body> 
    <div id=meter></div> 
    </body> 
</html> 

#meter { 
    width: 500px; 
    height: 15px; 
    margin: 2px 0; 
    background: green; 
    -webkit-transition; 
    width .05s; 
} 

function() { 
    var ctx = new webkitAudioContext(), 
    url = 'test.mp3', 
    audio = new Audio(url), 
    processor = ctx.createJavaScriptNode(2048, 1, 1), 
    meter = document.getElementById('meter'), 
    source; 

    audio.addEventListener('canplaythrough', function() { 
     source = ctx.createMediaElementSource(audio); 
     source.connect(processor); 
     source.connect(ctx.destination); 
     processor.connect(ctx.destination); 
     audio.play(); 
    }, false); 

    processor.onaudioprocess = function(evt) { 
     var input = evt.inputBuffer.getChannelData(0), 
     len = input.length, 
     total = i = 0, 
     rms; 
     while(i<len) 
      total += Math.abs(input[i++]); 
     rms = Math.sqrt(total/len); 
     meter.style.width = (rms*100) + '%'; 
    }; 
}; 

그것이 무엇을하는지 나는 정말로 모르겠다. 누구든지 나에게 더 많은 정보를 줄 수 있습니까?

+0

를 호출합니다. 제발 [ask]를보십시오 –

+0

하나의 링크를 클릭하는 것은 실제로 인터넷 주위를 쫓는 것이 아닙니다 ... 그러나 나는 그 질문을 편집 할 것입니다. – Sonofblip

+0

코드가 무엇을하고 있는지 설명 할 사람을 물어 보았습니까? 그렇지 않습니다. 귀하의 질문은 명확하지 않습니다. – jaket

답변

3

코드는 당신이 소멸 한 API를 교체하면 RMS 출력을 생성하지 난 당신의 코드를 찾고 인터넷 둘레 쫓고 있지 않다

old webkitAudioContext 
new  


try { 

    window.AudioContext = window.AudioContext || 
     window.webkitAudioContext || 
     window.mozAudioContext || 
     window.oAudioContext || 
     window.msAudioContext; 

    ctx = new AudioContext(); 

    console.log("cool audio context established ... ctx "); 

} catch (e) { 

    alert("Web Audio API is not supported by this browser\n ... http://caniuse.com/#feat=audio-api"); 
} 

old createJavaScriptNode 
new createScriptProcessor