收藏
回答

微信wx.getRecorderManager方法设置音频格式为pcm,原始格式还是webm格式?

startRecording() {

      const _this = this;

      if (_this.isRecording) {

        _this.recorderManager.stop();

      } else {

        _this.onWebSocketHandle();

        _this.recorderManager = Taro.getRecorderManager();

        _this.recorderManager.onStart(() => {

          console.log("recorder start");

          _this.isRecording = true;

        });

        _this.recorderManager.onPause(() => {

          console.log("recorder pause");

        });

        _this.recorderManager.onStop((res) => {

          console.log("recorder stop", res);

          const { tempFilePath, fileSize } = res;

          _this.isRecording = false;

          // _this.sendAudioStream(tempFilePath, fileSize);

          _this.$emit("stopRecorePushList", {

            audioBlob: tempFilePath,

          })

        });

        _this.recorderManager.onFrameRecorded((res) => {

          console.log("recorder onFrameRecorded", res);

          const { frameBuffer, isLastFrame } = res;

          console.log(

            "frameBuffer",

            frameBuffer,

            "frameBuffer.byteLength",

            frameBuffer.byteLength,

            isLastFrame

          );

          _this.sendWebsocketHandle(frameBuffer, isLastFrame);

        });

        const options = {

          duration: 60000,

          sampleRate: 48000,

          numberOfChannels: 1,

          encodeBitRate: 64000 ,

          format: "pcm",

          frameSize: 3,

        };

        _this.recorderManager.start(options);

      }

    },sendWebsocketHandle(frameBuffer, isLastFrame) {

      // // 将 ArrayBuffer 转换为 Int16Array(小端序)

      // const int16Array = new Int16Array(frameBuffer);

      // // 转换为小端序的 ByteBuffer(模拟 Java 的 ByteBuffer)

      // const byteBuffer = new ArrayBuffer(int16Array.length * 2);

      // const dataView = new DataView(byteBuffer);

      // for (let i = 0; i < int16Array.length; i++) {

      //   dataView.setInt16(i * 2, int16Array[i], true); // true 表示小端序

      // }

       const uint8Array = new Uint8Array(frameBuffer);

      console.log('uint8Array', uint8Array);


      console.log('frameBuffer', frameBuffer);

      // 发送数据(通过 WebSocket)

      this.socketTask.send({ data: frameBuffer, binary: true });

      if (isLastFrame) {

        this.sendWebsocketEndHandle();

      }

    }, 我需要格式为pcm格式的音频流。生成音频文件下载下来使用FFmpeg查看还是webm格式

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

1 个回答

  • 再见,电脑崽
    再见,电脑崽
    2025-10-31

    真机应该application/octet-stream,开发者工具是video/webm。

    2025-10-31
    有用
    回复
登录 后发表内容