新建一个record页面
record.wxml
<!--pages/record.wxml-->record.js
<button bindtap="startRecord">开始录音</button>
<button bindtap="stopRecord">停止录音</button>
// pages/record.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
startRecord: function () {
if (this.recorderManager == null) {
this.recorderManager = wx.getRecorderManager();
this.options = {
duration: 10000,
sampleRate: 16000,
numberOfChannels: 1,
encodeBitRate: 64000,
format: 'mp3',
frameSize: 50
}
}
this.recorderManager.start(this.options);
this.recorderManager.onStop((res) => {
console.log(res)
wx.uploadFile({
url: 'https://www.bfw.wiki/save.php', //将录音文件传到后台服务器
filePath: res.tempFilePath,
method: 'POST',
name: 'file',
header: {
'content-type': 'multipart/form-data'
},
success: function (res) {
console.log(res);
},
fail: function () {
console.log("语音识别失败");
}
})
});
},
stopRecord: function () {
this.recorderManager.stop()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
网友回复
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?


