收藏
回答

录音如何获取f32 pcm信息?

const recorder = wx.getRecorderManager();
  wx.connectSocket({
    url: "ws://192.168.0.102:19888/record",
    header: {
      Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxODIsImlhdCI6MTc1NDk2NjU0MSwiZXhwIjoxNzU1MDUyOTQxfQ.eV3IaQ6004Dn9XzUly86zoNo5rHVGDw9UTqOyPFoF9w`,
    },
  });
  wx.onSocketMessage((res) => {
    console.log(res);
  });
  wx.onSocketOpen((res) => {
    recorder.onFrameRecorded((res) => {
      if (res.isLastFrame) {
        console.log("record done");
      }
      const u8 = new Uint8Array(res.frameBuffer);
      const f32 = new Float32Array(u8.buffer, u8.byteOffset, u8.byteLength / 4);
      console.log(u8, f32);
      wx.sendSocketMessage({
        data: f32.buffer,
      });
    });


    recorder.start({
      sampleRate: 16000,
      numberOfChannels: 1, 
      format: "PCM",
      frameSize: 1
    });
  });
  wx.onSocketError((res) => {
    console.log("WebSocket连接打开失败,请检查!");
    recorder.stop();
  });
  wx.onSocketClose((res) => {
    console.log("WebSocket连接已关闭!");
    recorder.stop();
  });

目前得到的pcm数据都是错误的。不是-1 到 1 之间,而且有大量的NaN

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容