微信小程序录音开发

第一步,

<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();
  }
})

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

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

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

 

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端_李嘉豪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值