如何使用WebaudioAPI在浏览器上播放ArrayBufferstream?

我有一个独立的设备,使用ffmpeg和streamaudio到我的节点服务器。 我使用ffmpeg命令对stream进行编码

ffmpeg -f alsa -i hw:0 -acodec mp2 -f mp3 -r 30 http://localhost:8086/abc 

输出:

 ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers built on Oct 22 2013 12:31:55 with gcc 4.6.3 [alsa @ 0x20ef9c0] Estimating duration from bitrate, this may be inaccurate Input #0, alsa, from 'hw:0': Duration: N/A, start: 10088.609013, bitrate: N/A Stream #0.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s Output #0, mp3, to 'http://localhost:8086/abc': Metadata: TSSE : Lavf53.21.1 Stream #0.0: Audio: mp2, 48000 Hz, 2 channels, s16, 128 kb/s Stream mapping: Stream #0.0 -> #0.0 Press ctrl-c to stop encoding size= 462kB time=29.54 bitrate= 128.0kbits/s 

我正在使用networking套接字,然后将stream写入所有连接的客户端。 stream看起来像这样

 request.on('data', function(data){ console.log(data); audioSocket.broadcast(data, {binary:true}); }); //stream output <Buffer 78 00 dc ff 3b 00 1e 00 27 00 0d 00 72 00 f7 ff 4f 00 0e 00 7d 00 f5 ff 43 00 e2 ff 15 00 e5 ff 3e 00 db ff e9 ff d6 ff 24 00 ad ff ad ff a3 ff a3 ff 53 ...> 

我试图播放这个stream使用networkingaudioAPI,但我一直无法通过decodeAudioData步骤。 它总是调用错误callback,err始终为空。

 var audio = new WebSocket('ws://localhost:8088/'); audio.binaryType = "arraybuffer"; var context = new webkitAudioContext(); audio.onmessage = function(data){ var buf = data.data; d = data; context.decodeAudioData( buf, function(buffer){ console.log(buffer); }, //success handler function(err){ console.log('error: ', err) } //error handler ); } 

我怎样才能得到这个stream?