接收websocket发过来的base64音频数据,在通过audiocontext.decodeAudioData时总是失败,解码错误。请大家指教下,谢谢
代码如下:
1 playAudio : function(data){ 2 var arraybuff = Base64Binary.decodeArrayBuffer(data); 3 this.audioCtx.decodeAudioData(arraybuff, function(buffer) {//解码成pcm流 4 console.log("OK:"+data); 5 Studio.playSound(buffer); 6 },function(e){ 7 console.log("FAIL:"+data); 8 }); 9 }, 10 playSound:function(buffer){ 11 var source = this.audioCtx.createBufferSource(); 12 source.buffer = buffer; 13 source.connect(this.audioCtx.destination); 14 source.start(0); 15 },
undefined:1 Uncaught (in promise) DOMException: Unable to decode audio data
这是个解码的问题。
请教下你知道怎么转吗,服务端是 aac -> encode base64 ,我这边收到后就是个decode base64 ->decode pcm
pcm再转成wav即可解码成功播放
.....