diff --git a/src/views/voice/recordPage/index.vue b/src/views/voice/recordPage/index.vue index b97487b..07ae3d6 100644 --- a/src/views/voice/recordPage/index.vue +++ b/src/views/voice/recordPage/index.vue @@ -15,11 +15,12 @@ 重置 确定 -
+
猜您想找:
-
-
{{item.hotWordName}}
- +
+
+ {{ item.hotWordName }} +
@@ -54,14 +55,16 @@ const timEnd = ref(null); const settimEnd = ref(null); +const judgmentClose = ref(null); //记录10秒后的定时器 + const data = reactive({ showModal: false, //展示对话框 recordStatus: null, //录音进程的当前位置 miao: 0, recognizeWs: null, }); -const isGuess=ref(false) -const guessArr=ref({}) +const isGuess = ref(false); +const guessArr = ref({}); onMounted(() => { // 绑定事件-打印的是当前录音数据 @@ -78,19 +81,17 @@ //初始化语音调度websocket服务 function initRecognizeWs() { - if (data.recognizeWs) { - data.recognizeWs.onclose(); - } + data.recognizeWs && data.recognizeWs.close(); + data.recognizeWs && data.recognizeWs.onclose(); + let wsuri; if (window.location.protocol.includes('https')) { wsuri = `wss://${window.location.host}/voiceWebsocket`; } else { - // wsuri = `ws://192.168.20.43:8102/voiceWebsocket`; + wsuri = `ws://192.168.20.43:8102/voiceWebsocket`; // wsuri = `ws://139.155.49.237:8201/voiceWebsocket`; - wsuri = `ws://${window.location.host}/voiceWebsocket`; + // wsuri = `ws://${window.location.host}/voiceWebsocket`; // wsuri = `ws://server1.wh-nf.cn:8201/voiceWebsocket`; - - } data.recognizeWs = new WebSocket(wsuri); @@ -106,8 +107,12 @@ }; data.recognizeWs.onmessage = function (e) { - console.log('eeee', e); - if (e.data != '客户端连接成功') { + if (e.data == 'notice') { + GetTimeClose(e); + // 书写一个11秒后的定时器 如果10秒后收到信息就清除定时器 否则11秒后就重新连接 + } else if (e.data != '客户端连接成功' && e.data != 'notice') { + console.log('eeee', e); + let data = JSON.parse(e.data); let params = data.data; console.log('Websocket接收值', data); @@ -116,21 +121,18 @@ if (uploadbusinessSourceCode.value == data.type) { // 将返回的type数据与语音指令的业务code进行精准匹配 如果匹配上了 才说明是发送的这条数据 nowword.value = params.recognitionResult; - if(params.recognitionResult==''){ - nowword.value = `指令未识别,请重试`; - return + if (params.recognitionResult == '') { + nowword.value = `指令未识别,请重试`; + return; } - if (params.recognitionActionCode == 'error'||params.recognitionDataSourceCode=='error') { + if (params.recognitionActionCode == 'error' || params.recognitionDataSourceCode == 'error') { // nowword.value = `指令未识别,请您再说一遍`; - isGuess.value=true - guessArr.value=params - console.log('guessArr.value',guessArr.value); - + isGuess.value = true; + guessArr.value = params; + console.log('guessArr.value', guessArr.value); } else { - // 匹配业务来源编号去区分相关的操作 + // 匹配业务来源编号去区分相关的操作 switchRecognitionActionCode(params); - - } } } @@ -141,6 +143,14 @@ }; } +function GetTimeClose(e) { + console.log('进入定时器', e); + judgmentClose.value && clearTimeout(judgmentClose.value); + judgmentClose.value = setTimeout(() => { + initRecognizeWs(); + }, 11000); +} + // 匹配业务来源编号去区分相关的操作 function switchRecognitionActionCode(params) { console.log('params', params); @@ -164,18 +174,17 @@ break; } } -function resultClick(item){ - console.log('item',item); - let at=guessArr.value - let data={ - recognitionDataId:item.businessDataId, - recognitionActionCode: item.businessSourceCode=='path'?'open':'detail', +function resultClick(item) { + console.log('item', item); + let at = guessArr.value; + let data = { + recognitionDataId: item.businessDataId, + recognitionActionCode: item.businessSourceCode == 'path' ? 'open' : 'detail', // recognitionActionCode: at.recognitionActionCode == 'error'?at.actionList[0].businessSourceCode:at.recognitionActionCode, - recognitionDataSourceCode:item.businessSourceCode, - recognitionResult:at.recognitionResult, - } - switchRecognitionActionCode(data) - + recognitionDataSourceCode: item.businessSourceCode, + recognitionResult: at.recognitionResult, + }; + switchRecognitionActionCode(data); } async function dynamicPopUp(params) { console.log('params111', params); @@ -223,22 +232,20 @@ () => { // proxy.$modal.msgSuccess("获取权限成功,开始录音"); recorder.start().then(() => { - - data.showModal = true; -nowword.value = "开始录音,正在录音..."; + data.showModal = true; + nowword.value = '开始录音,正在录音...'; process.value = 2; - showSecond.value = 8; + showSecond.value = 8; - settimEnd.value = setTimeout(() => { - stopRecorderAndupload('stop'); - }, showSecond.value * 1000); + settimEnd.value = setTimeout(() => { + stopRecorderAndupload('stop'); + }, showSecond.value * 1000); - timEnd.value = setInterval(setTime, 1000); - + timEnd.value = setInterval(setTime, 1000); }); }, - (error) => { - proxy.$modal.msgError("请先允许该网页使用麦克风"); + error => { + proxy.$modal.msgError('请先允许该网页使用麦克风'); // console.log(`${error.name} : ${error.message}`); } ); @@ -300,11 +307,10 @@ // 机器人所用方法 function STARTVOICE() { console.log('process.value', process.value); - isGuess.value=false + isGuess.value = false; clearInterval(timEnd.value); if (process.value == 1) { startRecorder('begin'); - } else { showSecond.value = 0; clearTimeout(settimEnd.value); @@ -502,26 +508,26 @@ position: absolute; left: 0; bottom: -200px; - background: url('@/assets/images/pictureOnMap/contentBgc.png') no-repeat center; - background-size: 100% 100%; - .searchtext { - padding:5px ; - } - .Resultlist { - height: 170px; - overflow-y: auto; - padding: 0 10px; - - .eachMay { - margin-bottom: 5px; - cursor: pointer; - line-height: 22px; - padding-left: 5px; - } - .eachMay:hover{ - background: rgba(255,255,255,.2); - } - } + background: url('@/assets/images/pictureOnMap/contentBgc.png') no-repeat center; + background-size: 100% 100%; + .searchtext { + padding: 5px; + } + .Resultlist { + height: 170px; + overflow-y: auto; + padding: 0 10px; + + .eachMay { + margin-bottom: 5px; + cursor: pointer; + line-height: 22px; + padding-left: 5px; + } + .eachMay:hover { + background: rgba(255, 255, 255, 0.2); + } + } } } }