.wxml页面
<view class="voice-button" bindtouchstart="recordStart" bindtouchend="recordEnd">
<image class="pic-img" src="/resource/image/voice.png"></image>
<view class="pic-text">长按说话</view>
</view>
``
.wxss页面
.voice-button{
float: right;
text-align: center;
}
.pic-img{
width: 132rpx;
height: 132rpx;
}
.pic-text{
font-size: 26rpx;
}
.js页面
/* 语音功能 */
//这个是监听语音识别的方法,只要写了bindtouchstart和bindtouchend对应的方法就可自动触发,需注意的是,最好写var that = this;因为会发生指向问题,从而触发不到这个方法。
initRecord: function(){
let that = this;
//有新的识别内容返回,则会调用此事件
// manager.onRecognize = (res) => {
// var recText = this.sendRecord(res.tempFilePath);
// console.log('语音识别中');
// console.log(result);
// this.setData({
// inputVal: recText
// });
// }
// 识别结束事件
manager.onStop ((res) =&g