2017-12-01 25 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データを扱う例を提供することはできますか?

また、WebオーディオAPIを使用してライブストリーミングを処理する適切な方法はありますか?私はすでにこの問題についてほとんどすべての質問を読みましたが、どれも不具合なく動作するようです。何か案は?

答えて

1

あなたは一例として、このコードを実行できます。https://github.com/kmoskwiak/node-tcp-streaming-server

それは基本的にメディアソースの拡張機能を使用しています。あなたはビデオからオーディオに変更するだけです。

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

関連する問題