From 6a59f94278b4d05f5b7715b11b6dd0bfffc28cce Mon Sep 17 00:00:00 2001
From: 志浩 <neo.dzh@alibaba-inc.com>
Date: 星期四, 15 六月 2023 17:12:15 +0800
Subject: [PATCH] Merge branch 'main' into dev_dzh

---
 funasr/runtime/html5/static/main.js |   79 +++++++++++++++++++++++++++++++++------
 1 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 6548aa3..22f53c1 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -23,28 +23,61 @@
 var sampleBuf=new Int16Array();
 // 瀹氫箟鎸夐挳鍝嶅簲浜嬩欢
 var btnStart = document.getElementById('btnStart');
-btnStart.onclick = start;
+btnStart.onclick = record;
 var btnStop = document.getElementById('btnStop');
 btnStop.onclick = stop;
 btnStop.disabled = true;
+btnStart.disabled = true;
  
-
+btnConnect= document.getElementById('btnConnect');
+btnConnect.onclick = start;
  
-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;
+	console.log( "offline_text: " + asrmodel+","+offline_text);
+	console.log( "rec_text: " + rec_text);
 	 
  
 }
@@ -53,11 +86,14 @@
 function getConnState( connState ) {
 	if ( connState === 0 ) {
  
-		rec.open( function(){
-			rec.start();
-			console.log("寮�濮嬪綍闊�");
+		//rec.open( function(){
+		//	rec.start();
+		//	console.log("寮�濮嬪綍闊�");
  
-		});
+		//});
+		btnStart.disabled = false;
+		btnConnect.disabled = true;
+		info_div.innerHTML='杩炴帴鎴愬姛!璇风偣鍑诲紑濮�';
 	} else if ( connState === 1 ) {
 		//stop();
 	} else if ( connState === 2 ) {
@@ -66,11 +102,19 @@
 		 
 		alert("杩炴帴鍦板潃"+document.getElementById('wssip').value+"澶辫触,璇锋鏌sr鍦板潃鍜岀鍙o紝骞剁‘淇漢5鏈嶅姟鍜宎sr鏈嶅姟鍦ㄥ悓涓�涓煙鍐呫�傛垨鎹釜娴忚鍣ㄨ瘯璇曘��");
 		btnStart.disabled = true;
-		info_div.innerHTML='璇风偣鍑诲紑濮�';
+
+		info_div.innerHTML='璇风偣鍑昏繛鎺�';
 	}
 }
 
-
+function record()
+{
+		 rec.open( function(){
+		 rec.start();
+		 console.log("寮�濮�");
+		 btnStart.disabled = true;
+		 });
+}
 // 璇嗗埆鍚姩銆佸仠姝€�佹竻绌烘搷浣�
 function start() {
 	
@@ -78,14 +122,15 @@
 	clear();
 	//鎺т欢鐘舵�佹洿鏂�
  	    
-
+    info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
 	//鍚姩杩炴帴
 	var ret=wsconnecter.wsStart();
 	if(ret==1){
 		isRec = true;
 		btnStart.disabled = true;
 		btnStop.disabled = false;
-	    info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
+		btnConnect.disabled=true;
+
 	}
 }
 
@@ -97,7 +142,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);
@@ -114,7 +161,12 @@
 	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 = true;
+		btnConnect.disabled=false;
+		info_div.innerHTML="璇风偣鍑昏繛鎺�";}, 3000 );
 	rec.stop(function(blob,duration){
   
 		console.log(blob);
@@ -149,6 +201,7 @@
  
 	varArea.value="";
     rec_text="";
+	offline_text="";
  
 }
 

--
Gitblit v1.9.1