From b63e73ae4f5df9d4ed9fb0bee12ac2cc09d7f523 Mon Sep 17 00:00:00 2001
From: zhaomingwork <zhaomingwork@qq.com>
Date: 星期五, 19 五月 2023 14:30:13 +0800
Subject: [PATCH] add asr wss address input to html
---
funasr/runtime/html5/static/wsconnecter.js | 17 +++++++-
funasr/runtime/html5/readme.md | 7 +--
funasr/runtime/html5/static/index.html | 9 +++-
funasr/runtime/html5/readme_cn.md | 8 +--
funasr/runtime/html5/static/main.js | 25 +++++++++---
5 files changed, 46 insertions(+), 20 deletions(-)
diff --git a/funasr/runtime/html5/readme.md b/funasr/runtime/html5/readme.md
index 5dd462b..e60d588 100644
--- a/funasr/runtime/html5/readme.md
+++ b/funasr/runtime/html5/readme.md
@@ -41,13 +41,12 @@
```shell
python ws_server_online.py --port 5921
```
-## 3.modify asr address in wsconnecter.js according to your environment
-asr address in wsconnecter.js must be wss, just like
-var Uri = "wss://xxx:xxx/"
-## 4.open browser to access html5 demo
+## 3.open browser to access html5 demo
https://youraddress:port/static/index.html
+## 4.modify asr address in html according to your environment
+asr address in index.html must be wss
diff --git a/funasr/runtime/html5/readme_cn.md b/funasr/runtime/html5/readme_cn.md
index d7fb1aa..5037697 100644
--- a/funasr/runtime/html5/readme_cn.md
+++ b/funasr/runtime/html5/readme_cn.md
@@ -41,14 +41,12 @@
```shell
python ws_server_online.py --port 5921
```
-## 3.淇敼wsconnecter.js閲宎sr鎺ュ彛鍦板潃
-wsconnecter.js閲岄厤缃畂nline asr鏈嶅姟鍦板潃璺緞锛岃繖閲岄厤缃殑鏄痺ss绔彛
-var Uri = "wss://xxx:xxx/"
-## 4.娴忚鍣ㄦ墦寮�鍦板潃娴嬭瘯
+## 3.娴忚鍣ㄦ墦寮�鍦板潃娴嬭瘯,璇锋牴鎹疄闄卛p濉啓
https://127.0.0.1:1337/static/index.html
-
+## 4.淇敼缃戦〉閲宎sr鎺ュ彛鍦板潃
+鐩存帴缃戦〉閲屼慨鏀瑰悗锛岀偣鍑诲紑濮嬪嵆鍙娇鐢ㄣ�傛敞鎰廻5鏈嶅姟鍜宎sr鏈嶅姟闇�瑕佸湪鍚屼竴涓湇鍔″櫒涓婏紝鍚﹀垯瀛樺湪璺ㄥ煙闂銆�
## 鑷鐢熸垚璇佷功
diff --git a/funasr/runtime/html5/static/index.html b/funasr/runtime/html5/static/index.html
index 1cdc7d7..c0aae05 100644
--- a/funasr/runtime/html5/static/index.html
+++ b/funasr/runtime/html5/static/index.html
@@ -13,10 +13,15 @@
-
+ <h1>FunAsr H5 Demo</h1>
<div class="div_class_topArea">
-
+
<div class="div_class_recordControl">
+ asr鏈嶅姟鍣ㄥ湴鍧�(蹇呭~):
+ <br>
+ <input id="wssip" type="text" style=" width: 100%;height:100%" value="wss://127.0.0.1:5921/"/>
+ <br>
+ <br>
璇煶璇嗗埆缁撴灉鏄剧ず锛�
<br>
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 5f6bb10..eaa257a 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -32,7 +32,11 @@
var rec_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;
// 璇煶璇嗗埆缁撴灉; 瀵筳sonMsg鏁版嵁瑙f瀽,灏嗚瘑鍒粨鏋滈檮鍔犲埌缂栬緫妗嗕腑
function getJsonMessage( jsonMsg ) {
@@ -59,23 +63,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鏈嶅姟鍣紝璇风瓑寰�...";
+ }
}
diff --git a/funasr/runtime/html5/static/wsconnecter.js b/funasr/runtime/html5/static/wsconnecter.js
index 594652d..82d751b 100644
--- a/funasr/runtime/html5/static/wsconnecter.js
+++ b/funasr/runtime/html5/static/wsconnecter.js
@@ -5,7 +5,8 @@
/* 2021-2023 by zhaoming,mali aihealthx.com */
function WebSocketConnectMethod( config ) { //瀹氫箟socket杩炴帴鏂规硶绫�
- var Uri = "wss://30.220.136.139:5921/" // var Uri = "wss://30.221.177.46:5921/" //璁剧疆wss asr online鎺ュ彛鍦板潃 濡� wss://X.X.X.X:port/wss/
+
+
var speechSokt;
var connKeeperID;
@@ -13,16 +14,28 @@
var stateHandle = config.stateHandle;
this.wsStart = function () {
-
+ var Uri = document.getElementById('wssip').value; //"wss://111.205.137.58:5821/wss/" //璁剧疆wss asr online鎺ュ彛鍦板潃 濡� wss://X.X.X.X:port/wss/
+
+ if(Uri.match(/wss:\S*/))
+ {
+ console.log("Uri"+Uri);
+ }
+ else
+ {
+ alert("璇锋鏌ss鍦板潃姝g‘鎬�");
+ return 0;
+ }
if ( 'WebSocket' in window ) {
speechSokt = new WebSocket( Uri ); // 瀹氫箟socket杩炴帴瀵硅薄
speechSokt.onopen = function(e){onOpen(e);}; // 瀹氫箟鍝嶅簲鍑芥暟
speechSokt.onclose = function(e){onClose(e);};
speechSokt.onmessage = function(e){onMessage(e);};
speechSokt.onerror = function(e){onError(e);};
+ return 1;
}
else {
alert('褰撳墠娴忚鍣ㄤ笉鏀寔 WebSocket');
+ return 0;
}
};
--
Gitblit v1.9.1