From 2c9e9a69dba5481824f8ce89abe554fd0079b29a Mon Sep 17 00:00:00 2001
From: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com>
Date: 星期四, 25 五月 2023 19:30:26 +0800
Subject: [PATCH] add 2pass online offline select for ws html5 (#557)
---
funasr/runtime/html5/static/wsconnecter.js | 2 ++
funasr/runtime/html5/static/index.html | 7 +++++++
funasr/runtime/html5/static/main.js | 36 ++++++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/funasr/runtime/html5/static/index.html b/funasr/runtime/html5/static/index.html
index 3bc0fc8..b99a140 100644
--- a/funasr/runtime/html5/static/index.html
+++ b/funasr/runtime/html5/static/index.html
@@ -22,6 +22,13 @@
<input id="wssip" type="text" style=" width: 100%;height:100%" value="wss://127.0.0.1:1095/"/>
<br>
<br>
+ <div style="border:2px solid #ccc;">
+ 閫夋嫨asr妯″瀷妯″紡:<br/>
+ <label><input name="asr_mode" type="radio" value="2pass" checked="true"/>2pass </label>
+ <label><input name="asr_mode" type="radio" value="online" />online </label>
+ <label><input name="asr_mode" type="radio" value="offline" />offline </label>
+ </div>
+ <br>
璇煶璇嗗埆缁撴灉鏄剧ず锛�
<br>
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 6548aa3..be57df1 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -30,7 +30,8 @@
-var rec_text=""
+var rec_text="";
+var offline_text="";
var info_div = document.getElementById('info_div');
//var now_ipaddress=window.location.href;
@@ -38,12 +39,40 @@
//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;
@@ -97,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);
@@ -149,6 +180,7 @@
varArea.value="";
rec_text="";
+ offline_text="";
}
diff --git a/funasr/runtime/html5/static/wsconnecter.js b/funasr/runtime/html5/static/wsconnecter.js
index 82d751b..dfa8235 100644
--- a/funasr/runtime/html5/static/wsconnecter.js
+++ b/funasr/runtime/html5/static/wsconnecter.js
@@ -69,7 +69,9 @@
"wav_name": "h5",
"is_speaking": true,
"chunk_interval":10,
+ "mode":getAsrMode(),
};
+ console.log(request);
speechSokt.send( JSON.stringify(request) );
console.log("杩炴帴鎴愬姛");
stateHandle(0);
--
Gitblit v1.9.1