> 微信小程序开发教程手册 > 微信小程序API 录音

wx.startRecord(OBJECT)


开始录音。当主动调用wx.stopRecord,或者录音超过1分钟时自动结束录音,返回录音文件的临时文件路径

OBJECT参数说明:

参数 类型 必填 说明
success Function 录音成功后调用,返回录音文件的临时文件路径,res={tempFilePath:"录音文件的临时路径"}
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

wx.stopRecord()


​ 主动调用停止录音。

示例代码:

wx.starRecord({
  success:function(res){
     var tempFilePath = res.tempFilePath;  
  },
  fail:function(res){
     //录音失败
  }
});
setTimeout(function(){  
  //结束录音  
  wx.stopRecord();
},10000);