问题:微信传输给服务端的到底是什么格式?服务端按照pcm解析并不成功。
recorderManager.start({
format: 'PCM', // 如果是流式的话,只支持 mp3和pcm
sampleRate: 16000,
numberOfChannels: 1,
encodeBitRate: 64000,
frameSize:10
});
recorderManager.onFrameRecorded((res) => {
const data = res.frameBuffer;
// 直接发送PCM到服务端
global.client.sendAudioData(data);
});
服务端是python, 将微信返回的数据按照无头pcm转wav,里面全是噪音沙沙的,没有人声
python 代码
# pcm_data 将是微信通过websocket传过来的数据流
def pcm_to_wav(pcm_data, output_path, channels=1, sample_width=1, frame_rate=16000):
with wave.open(output_path, 'wb') as wav_file:
wav_file.setnchannels(channels)
wav_file.setsampwidth(sample_width) # 16-bit
wav_file.setframerate(frame_rate)
wav_file.writeframes(pcm_data)

我也遇到了 请问解决了没有?
看了python部分代码应该在录制后要先转16int数据才可以解析的,以下代码可以参考
this.recorderManager.onFrameRecorded((res) => { const sourceData = new Int16Array(res.frameBuffer) // const u8 = new Uint8Array(res.frameBuffer); // const f32 = new Float32Array(u8.buffer, u8.byteOffset, u8.byteLength / 4); console.log("录音分片", sourceData.buffer) // 模拟器上不行录制是OPUS编码音频,请在真机上调试PCM this.socket.send({ data: sourceData.buffer, success: (res) => { console.log("ws", res) } }); })请问楼主解决了吗
用真机调试看看