Эх сурвалжийг харах

add 2pass online offline select for ws html5 (#557)

zhaomingwork 2 жил өмнө
parent
commit
2c9e9a69db

+ 7 - 0
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>&nbsp;&nbsp;
+      <label><input name="asr_mode" type="radio" value="online" />online </label>&nbsp;&nbsp;
+      <label><input name="asr_mode" type="radio" value="offline" />offline </label> 
+				</div>
+				<br>
 				语音识别结果显示:
 				<br>
 				

+ 34 - 2
funasr/runtime/html5/static/main.js

@@ -30,7 +30,8 @@ btnStop.disabled = true;
  
 
  
-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 @@ var info_div = document.getElementById('info_div');
 //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;
+}
+		   
+
 // 语音识别结果; 对jsonMsg数据解析,将识别结果附加到编辑框中
 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 @@ function stop() {
 			"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 @@ function clear() {
  
 	varArea.value="";
     rec_text="";
+	offline_text="";
  
 }
 

+ 2 - 0
funasr/runtime/html5/static/wsconnecter.js

@@ -69,7 +69,9 @@ function WebSocketConnectMethod( config ) { //定义socket连接方法类
 			"wav_name":  "h5",
 			"is_speaking":  true,
 			"chunk_interval":10,
+			"mode":getAsrMode(),
 		};
+		console.log(request);
 		speechSokt.send( JSON.stringify(request) );
 		console.log("连接成功");
 		stateHandle(0);