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가 활성화되어, 또는 동일한 도메인에서 실행 스크립트에 있어야합니다)
왜이 코드는 firefox에서 작동하지 않습니까? https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader#Browser_compatibility : –
는 일부 플래그 지원 – jujule