2017-12-01 9 views
2
나는 nodejs의 소켓

웹 오디오 API 광고 : 소켓

window.AudioContext = window.AudioContext || window.webkitAudioContext; 
var context = new AudioContext(); 
var delayTime = 0; 
var init = 0; 
var audioStack = []; 
var nextTime = 0; 

client.on('stream', function(stream, meta){ 
    stream.on('data', function(data) { 
     context.decodeAudioData(data, function(buffer) { 
      audioStack.push(buffer); 
      if ((init!=0) || (audioStack.length > 10)) { // make sure we put at least 10 chunks in the buffer before starting 
       init++; 
       scheduleBuffers(); 
      } 
     }, function(err) { 
      console.log("err(decodeAudioData): "+err); 
     }); 
    }); 
}); 

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.05; /// 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 
    }; 
} 

오디오 덩어리를 해독하려면 다음 코드를 사용하고 있습니다하지만 약간의 차이/오디오 덩어리 사이의 결함을 가지고

통해 nodejs 서버에서 데이터 청크를 재생하는 적절한 방법 나는 알아낼 수 없다.

또한 MediaSource를 사용하면 플레이어가 수동으로 처리하는 대신 동일한 작업을 수행 할 수 있습니다. 누군가 mp3 데이터를 처리하는 예제를 제공 할 수 있습니까?

웹 오디오 API로 라이브 스트리밍을 처리하는 적절한 방법은 무엇입니까? 나는 이미이 주제에 관한 거의 모든 질문을 읽었으며 그 중 아무도 결함이없이 작동하지 않는 것으로 보인다. 어떤 아이디어?

답변

1

당신은 예를 들어이 코드를 수행 할 수 있습니다 https://github.com/kmoskwiak/node-tcp-streaming-server

그것은 기본적으로 미디어 소스 확장을 사용합니다. 비디오에서 오디오로 바꾸는 것만으로도 충분합니다.

buffer = mediaSource.addSourceBuffer('audio/mpeg');