微信小程序录音开发

第一步,

<view class='container'>
  <button bindtap='startRecording'>开始录音</button>
  <button bindtap='pauseRecording'>暂停录音</button>
  <button bindtap='resumeRecording'>继续录音</button>
  <button bindtap='stopRecording'>结束录音</button>
  <view>
    <view>时长:{{audioMsg.duration}}</view>
    <view>文件大小:{{audioMsg.fileSize}}</view>
    <view>临时路径:{{audioMsg.tempFilePath}}</view>
  </view>
</view>

第二步

var app = getApp();
var recorderManager = wx.getRecorderManager(); //录音管理

var options = {
  duration: 300000,
  sampleRate: 16000,
  numberOfChannels: 1,
  encodeBitRate: 48000,
  format: 'mp3',//这里是生成的音频文件格式
  frameSize: 50,
};
Page({

  data: {
    audioMsg:{}
  },
  onLoad(){
    var that = this
    //监听录音结束 并返回本地MP3文件
    recorderManager.onStop((res) => {
      that.setData({
        audioMsg:res
      })
      console.log(res)
    })
  },
  //开始录音
  startRecording(){
    recorderManager.start(options)
    console.log('开始')
  },
  //暂停录音
  pauseRecording() {
    recorderManager.pause();
    console.log('暂停')
  }, 
  //继续录音
  resumeRecording(){
    recorderManager.resume();
  },
  //结束录音
  stopRecording() {
    recorderManager.stop();
  }
})

其实很简单,并没有那么复杂,拿到临时地址,上传服务器就可以了,

如果需要延伸的小伙伴可以私聊我,

有帮助到大家的记得关注噢~

 

喜欢上方小程序,需要源码的,私信小编留下邮箱。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章