调用语音转文字接口,长时间静默录音,有大概率rsp返回极慢,高达6s以上,小概率没有回调函数rsp
// 监听录音开始事件 recorder.onStart = (res) => { this.setData({ recordLoading: '录音中' }) const {selectedStyle, selectedCharacter} = this.data; voiceAi.setChatSetting(selectedStyle); voiceAi.setVoiceSetting(selectedCharacter); console.log("成功开始录音识别", res) } // 监听录音结束事件 recorder.onStop = (res) => { console.log("result: ", res.result) console.log('duration: ', res.duration) if(! res.result) { this.setData({ recordLoading: '', showRecordModal: false }) console.log('res.result false') wx.showToast({ title: '未识别到文字', icon: 'none', duration: 1500 }) } else { wx.showToast({ title: res.result, icon: 'none', duration: 1500 }) voiceAi.getLLM(res.result, (answer) => { if (answer) { voiceAi.sendToTTSAndPlay(answer, ()=> { this.setData({ //recordLoading: '语音播放中..' showRecordModal: false }) } /*, ()=> { this.setData({ recordLoading: '', showRecordModal: false }) }*/); } else { console.warn("未能获取到LLM返回的文本"); } }) } } // 添加错误日志监控 recorder.onError = (err) => { console.error("error: ", err) if (err.retcode === -30004) { wx.showToast({ title: '未识别到语音内容', icon: 'none' }); } else { wx.showToast({ title: '语音识别失败', icon: 'none' }); } this.setData({ recordLoading: '', showRecordModal: false }) }; handleGlobalTouchEnd() { if (this.data.isRecording === true) { console.log('handleGlobalTouchEnd') // 移除录音状态 this.setData({ isRecording: false, recordLoading: '语音处理中...' }) recorderManager.stop() } }, //录音按钮长按 handleLongPress() { if(this.data.isRecording) { console.log('当前状态不可录音'); return; } console.log('handleLongPress') const recorder = recorderManager this.setData({ isVoiceBtnLongPress: true, showRecordModal: true, isRecording: true, recordLoading: '加载中' }) // 添加录音动画 this.startRippleAnimation(); recorder.start({duration:10000, lang: "zh_CN"}) },