2016-07-26 2 views
0

Chrome 51을 사용하여 가져 오기 API에서 오는 무한 스트림을 재생하려고합니다 (Microsoft PCM, 16 비트, 모노 11025 Hz와 같은 웹캠 오디오 스트림)가져 오기가 포함 된 WebAudio 스트리밍 : DOMException : 오디오 데이터를 디코딩 할 수 없습니다.

코드가이 각색

: 내가 "오디오 데이터를 디코딩 할 수 없습니다 예외 : DOMException"를 얻을

코드는 몇 가지 결함을 제외하고, MP3 파일 파일과 거의 확인을 작동하지만, 어떤 이유로 wav 파일로 전혀 작동하지 않습니다 Choppy/inaudible playback with chunked audio through Web Audio API

의 수는이 WAV 스트림과 함께 작동하도록하면 어떤 생각을 대답?

function play(url) { 
    var context = new (window.AudioContext || window.webkitAudioContext)(); 
    var audioStack = []; 
    var nextTime = 0; 

    fetch(url).then(function(response) { 
    var reader = response.body.getReader(); 
    function read() { 
     return reader.read().then(({ value, done })=> { 
     context.decodeAudioData(value.buffer, function(buffer) { 
      audioStack.push(buffer); 
      if (audioStack.length) { 
       scheduleBuffers(); 
      } 
     }, function(err) { 
      console.log("err(decodeAudioData): "+err); 
     }); 
     if (done) { 
      console.log('done'); 
      return; 
     } 
     read() 
     }); 
    } 
    read(); 
    }) 

    function scheduleBuffers() { 
     while (audioStack.length) { 
      var buffer = audioStack.shift(); 
      var source = context.createBufferSource(); 
      source.buffer = buffer; 
      source.connect(context.destination); 
      if (nextTime == 0) 
       nextTime = context.currentTime + 0.01; /// add 50ms latency to work well across systems - tune this if you like 
      source.start(nextTime); 
      nextTime += source.buffer.duration; // Make the next buffer wait the length of the last buffer before being played 
     }; 
    } 
} 

play ('/ path/to/mp3')를 사용하여 코드를 테스트하면됩니다. (서버는 CORS가 활성화되어, 또는 동일한 도메인에서 실행 스크립트에 있어야합니다)

답변

0

일부 웹 오디오 마법과 PAQUET 주문 확인 레이몬드 제안으로 WAV 스트림 사운드가 제대로 청크에 WAV 헤더를 추가하는 의미 만들기, 플러스; https://github.com/revolunet/webaudio-wav-stream-player

지금 일부 구성 플래그 57+ 파이어 폭스에서 작동 : https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader#Browser_compatibility

+0

왜이 코드는 firefox에서 작동하지 않습니까? https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader#Browser_compatibility : –

+1

는 일부 플래그 지원 – jujule

1

AudioContext.decodeAudioData 단지 일부 파일을 디코딩하도록 설계되지 않았습니다; "짧은"(그러나 완전한) 파일을위한 것입니다. MP3의 덩어리 설계로 인해 MP3 스트림에서 작동하지만 WAV 파일에서는 작동하지 않는 경우가 있습니다. 이 경우 자신의 디코더를 구현해야합니다.

+1

아니면 WAV 헤더를 앞에 추가

멋진 사람은 모듈이 단지를 처리하고 크롬에 ​​아름답게 작동 설정에 저를 도와 'decodeAudioData'를 호출하기 전에 PCM 데이터의 각 덩어리에. WAV 헤더는 정말 간단합니다. –

+0

감사 레이몬드 ...이 ... 나를 위해 어떻게 헤더를 정의하고 덩어리로 씁니다 어떤 생각을 좋은 해결 방법을 소리? – jujule

+0

여기에서 아이디어를 실험 해보십시오 : https://gist.github.com/revolunet/46d4187c3b6f28632a91421c1f2a9fad – jujule

관련 문제