initRecord: function () {
const that = this;
// 有新的识别内容返回,则会调用此事件
manager.onRecognize = function (res) {
console.log(res,'6789765678')
}
// 正常开始录音识别时会调用此事件
manager.onStart = function (res) {
console.log("成功开始录音识别", res)
}
// 识别错误事件
manager.onError = function (res) {
console.error("error msg", res)
}
//识别结束事件
manager.onStop = function (res) {
console.log(res,'99999999999')
console.log('..............结束录音')
console.log('录音临时文件地址 -->' + res.tempFilePath);
console.log('录音总时长 -->' + res.duration + 'ms');
console.log('文件大小 --> ' + res.fileSize + 'B');
console.log('语音内容 --> ' + res.tempFilePath);
if (res.tempFilePath == '') {
wx.showModal({
title: '提示',
content: '听不清楚,请重新说一遍!',
showCancel: false,
success: function (res) {}
})
return;
}
//var text = that.data.content + res.result;
var text = res.result;
console.log('语音内容 -->text ' + text);
console.log('语音内容 -->that.data.flag ' + that.data.flag);
if(that.data.flag == 1){
that.setData({
recordStatus: 1,
waiding:0,//等待提示
content: text,
inputValue:text,
})
that.bindSays();
//that.readAiText();
}
}
},
//语音 --按住说话
touchStart: function (e) {
var flag = Number(e.currentTarget.dataset.flag)
console.log("touchStart.e:" , e)
let detail = e.detail || {}
let buttonItem = detail.buttonItem || {}
if (!startOver){
endEnable = false;
return;
}else{
startOver = false;
endEnable = true;
}
// manager.stop();
startTime = new Date().getTime();
console.log("点击开始:" + startTime)
recordState=true;
setTimeout(function(){
if (!recordState){
console.log("时间小于0.5秒,认为误点,不进行录音");
startOver = true;
return;
}
console.log("开始录音,调用manager.start()")
manager.start({
duration:60000,
lang: 'zh_CN',// 识别的语言,目前支持zh_CN en_US zh_HK sichuanhua
});
console.log("开始录音,调用manager.start完成")
startOver = true;
},500)
this.setData({
recordStatus: 0,
recording: true,
waiding:1,//等待提示
waidingMSG: '让我想想..',
recordState: true, //录音状态
flag:flag
})
// 语音开始识别
//manager.start({ duration: 30000, lang: "zh_CN" })
},
//语音 --松开结束
touchEnd: function (e) {
console.log("touchEnd.e:" ,e)
let detail = e.detail || {} // 自定义组件触发事件时提供的detail对象
let buttonItem = detail.buttonItem || {}
// 防止重复触发stop函数
if(!this.data.recording || this.data.recordStatus != 0) {
console.warn("has finished!");
return
}
// 语音结束识别
manager.stop();
this.setData({
bottomButtonDisabled: true,
recordState: false,
})
},