From 2c5c356ca09383a0900402890aa94edd4a60b64c Mon Sep 17 00:00:00 2001 From: "yanyuxiyangzk@126.com" Date: Sun, 14 Apr 2024 19:15:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=A1=B5=E9=9D=A2=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E8=AF=86=E5=88=AB=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/static/echo.html | 5 ++++- html/static/main.js | 32 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/html/static/echo.html b/html/static/echo.html index ad0c63c..7e24dbc 100644 --- a/html/static/echo.html +++ b/html/static/echo.html @@ -13,7 +13,7 @@

metahuman voice test

-
+

input text

@@ -125,5 +125,8 @@ // $('#message').val(''); // }); // }); + + + \ No newline at end of file diff --git a/html/static/main.js b/html/static/main.js index 9cd2919..52ff5c0 100644 --- a/html/static/main.js +++ b/html/static/main.js @@ -50,7 +50,7 @@ var file_data_array; // array to save file data var totalsend=0; -const startTime = Date.now(); +var startTime = Date.now(); var now_ipaddress=window.location.href; now_ipaddress=now_ipaddress.replace("https://","wss://"); @@ -347,21 +347,28 @@ function handleWithTimestamp(tmptext,tmptime) // 语音识别结果; 对jsonMsg数据解析,将识别结果附加到编辑框中 function getJsonMessage( jsonMsg ) { - const currentTime = Date.now(); - res_time = startTime-currentTime; + if(!recive_msg) return; + var currentTime = Date.now(); + res_time = currentTime-startTime; + console.log(res_time) //时间之差在4秒则发送消息 - let waitTime = 5000; - if(res_time>=waitTime){ + let waitTime = 15000; + if(res_time>waitTime){ //自动发送消息 - ('#echo-form').on('submit', function(e) { + var f = document.getElementById("echo-form"); + f.submit = function(e){ e.preventDefault(); - var message = $('#message').val(); + var message=document.getElementById('message').value; console.log('Sending: ' + message); ws.send(message); - $('#message').val(''); - }); - + document.getElementById('message').value=''; + } + + recive_msg = false; startTime = currentTime; + // rec_text=""; + // var varArea_message=document.getElementById('message'); + // varArea_message.value=""; return; } @@ -371,6 +378,8 @@ function getJsonMessage( jsonMsg ) { //console.log(jsonMsg); console.log( "message: " + JSON.parse(jsonMsg.data)['text'] ); var rectxt=""+JSON.parse(jsonMsg.data)['text']; + + var asrmodel=JSON.parse(jsonMsg.data)['mode']; var is_final=JSON.parse(jsonMsg.data)['is_final']; var timestamp=JSON.parse(jsonMsg.data)['timestamp']; @@ -592,7 +601,7 @@ function recProcess( buffer, powerLevel, bufferDuration, bufferSampleRate,newBuf } } - +var recive_msg = true; $(document).ready(function() { var host = window.location.hostname var ws = new WebSocket("ws://"+host+":8000/humanecho"); @@ -602,6 +611,7 @@ $(document).ready(function() { }; ws.onmessage = function(e) { console.log('Received: ' + e.data); + recive_msg = true; data = e var vid = JSON.parse(data.data); console.log(typeof(vid),vid)