解决了嘛
decodeAudioData后的音频数据拼接播放有卡顿,要如何解决?服务端流式返回音频数据,每个chunk经过decodeAudioData后,将其中的buffer进行拼接,块与块之间会存在卡顿。请问是服务端返回的音频数据格式有问题吗?还是拼接方式有问题? const audioCtx = Taro.createWebAudioContext(); let tempList = []; const task = wx.request({}) task.onChunkReceived((res) => { audioCtx.decodeAudioData( res.data, (buffer) => { tempList = [...tempList, buffer]; }, (err) => {} ); }); setTimeout(() => { const buffer = audioCtx.createBuffer(1, tempList.reduce((pre, item) => item.length + pre, 0), 44100); let seek = 0; for (let i = 0; i < tempList.length; ++i) { buffer.copyToChannel(tempList[i].getChannelData(0), 0, seek); seek += tempList[i].length; } const source = audioCtx.createBufferSource(); source.buffer = buffer; source.connect(audioCtx.destination); source.start(); }, 5000);
2024-08-18