From fae856e23d45fd27d5fd55fd036e8e3fc7b24915 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期五, 02 六月 2023 23:00:08 +0800
Subject: [PATCH] update funasr-onnx-offline
---
funasr/runtime/html5/static/main.js | 65 +++++++++++++++++++++++++++-----
1 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 5f6bb10..9317778 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -30,16 +30,49 @@
-var rec_text=""
+var rec_text="";
+var offline_text="";
var info_div = document.getElementById('info_div');
-
+
+//var now_ipaddress=window.location.href;
+//now_ipaddress=now_ipaddress.replace("https://","wss://");
+//now_ipaddress=now_ipaddress.replace("static/index.html","");
+//document.getElementById('wssip').value=now_ipaddress;
+
+function getAsrMode(){
+
+ var item = null;
+ var obj = document.getElementsByName("asr_mode");
+ for (var i = 0; i < obj.length; i++) { //閬嶅巻Radio
+ if (obj[i].checked) {
+ item = obj[i].value;
+ break;
+ }
+
+
+ }
+ console.log("asr mode"+item);
+ return item;
+}
+
// 璇煶璇嗗埆缁撴灉; 瀵筳sonMsg鏁版嵁瑙f瀽,灏嗚瘑鍒粨鏋滈檮鍔犲埌缂栬緫妗嗕腑
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'];
+ if(asrmodel=="2pass-offline")
+ {
+ offline_text=offline_text+rectxt.replace(/ +/g,"");
+ rec_text=offline_text;
+ }
+ else
+ {
+ rec_text=rec_text+rectxt.replace(/ +/g,"");
+ }
var varArea=document.getElementById('varArea');
- rec_text=rec_text+rectxt.replace(/ +/g,"");
+
varArea.value=rec_text;
@@ -59,23 +92,30 @@
} else if ( connState === 2 ) {
stop();
console.log( 'connecttion error' );
- setTimeout(function(){btnStart.disabled = true;info_div.innerHTML='connecttion error';}, 4000 );
+
+ alert("杩炴帴鍦板潃"+document.getElementById('wssip').value+"澶辫触,璇锋鏌sr鍦板潃鍜岀鍙o紝骞剁‘淇漢5鏈嶅姟鍜宎sr鏈嶅姟鍦ㄥ悓涓�涓煙鍐呫�傛垨鎹釜娴忚鍣ㄨ瘯璇曘��");
+ btnStart.disabled = true;
+ info_div.innerHTML='璇风偣鍑诲紑濮�';
}
}
// 璇嗗埆鍚姩銆佸仠姝€�佹竻绌烘搷浣�
function start() {
- info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
+
// 娓呴櫎鏄剧ず
clear();
//鎺т欢鐘舵�佹洿鏂�
- isRec = true;
- btnStart.disabled = true;
- btnStop.disabled = false;
+
//鍚姩杩炴帴
- wsconnecter.wsStart();
+ var ret=wsconnecter.wsStart();
+ if(ret==1){
+ isRec = true;
+ btnStart.disabled = true;
+ btnStop.disabled = false;
+ info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
+ }
}
@@ -86,7 +126,9 @@
"wav_name": "h5",
"is_speaking": false,
"chunk_interval":10,
+ "mode":getAsrMode(),
};
+ console.log(request);
if(sampleBuf.length>0){
wsconnecter.wsSend(sampleBuf,false);
console.log("sampleBuf.length"+sampleBuf.length);
@@ -103,7 +145,9 @@
isRec = false;
info_div.innerHTML="璇风瓑鍊�...";
btnStop.disabled = true;
- setTimeout(function(){btnStart.disabled = false;info_div.innerHTML="璇风偣鍑诲紑濮�";}, 3000 );
+ setTimeout(function(){
+ console.log("call stop ws!");
+ wsconnecter.wsStop();btnStart.disabled = false;info_div.innerHTML="璇风偣鍑诲紑濮�";}, 3000 );
rec.stop(function(blob,duration){
console.log(blob);
@@ -138,6 +182,7 @@
varArea.value="";
rec_text="";
+ offline_text="";
}
--
Gitblit v1.9.1