微信小程序录音

400 阅读1分钟

花了一周空闲时间撸了一个小程序 先上图😁

您的祝福

1.录音

 * 获取全局唯一的录音管理器
 * 配置录音参数 options 
 * 录音回调函数处理
// 录音管理器
const rm = wx.getRecorderManager() 
// 录音参数
const options = {
      duration: 60000, //录音的时长,单位 ms
      sampleRate: 44100, //采样率
      numberOfChannels: 1, //录音通道数
      encodeBitRate: 192000, //编码码率
      format: 'mp3', //音频格式
      frameSize: 50 //指定帧大小,单位 KB
    }
// 开始录音
rm.start(options)
// 录音回调函数
rm.onStart((res) => {
  // 监听录音开始事件
})
rm.onPaus((res) => {
  // 监听录音暂停事件
})
rm.onResume((res) => {
  // 监听录音继续事件
})
rm.onStop((res) => {
  // 监听录音结束事件
})

2.效果图