From 8706e767affc6bdc8cb7a67ca3a20a62779ff048 Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期三, 17 五月 2023 15:45:46 +0800
Subject: [PATCH] Merge branch 'main' of https://github.com/alibaba-damo-academy/FunASR into main
---
funasr/runtime/html5/static/wsconnecter.js | 81 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/funasr/runtime/html5/static/wsconnecter.js b/funasr/runtime/html5/static/wsconnecter.js
new file mode 100644
index 0000000..4b22e8f
--- /dev/null
+++ b/funasr/runtime/html5/static/wsconnecter.js
@@ -0,0 +1,81 @@
+/**
+ * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights
+ * Reserved. MIT License (https://opensource.org/licenses/MIT)
+ */
+/* 2021-2023 by zhaoming,mali aihealthx.com */
+
+function WebSocketConnectMethod( config ) { //瀹氫箟socket杩炴帴鏂规硶绫�
+ var Uri = "wss://111.205.137.58:5821/wss/" //璁剧疆wss asr online鎺ュ彛鍦板潃 濡� wss://X.X.X.X:port/wss/
+ var speechSokt;
+ var connKeeperID;
+
+ var msgHandle = config.msgHandle;
+ var stateHandle = config.stateHandle;
+
+ this.wsStart = function () {
+
+ 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);};
+ }
+ else {
+ alert('褰撳墠娴忚鍣ㄤ笉鏀寔 WebSocket');
+ }
+ };
+
+ // 瀹氫箟鍋滄涓庡彂閫佸嚱鏁�
+ this.wsStop = function () {
+ if(speechSokt != undefined) {
+ speechSokt.close();
+ }
+ };
+
+ this.wsSend = function ( oneData,stop ) {
+
+ if(speechSokt == undefined) return;
+ if ( speechSokt.readyState === 1 ) { // 0:CONNECTING, 1:OPEN, 2:CLOSING, 3:CLOSED
+
+ speechSokt.send( oneData );
+ if(stop){
+ setTimeout(speechSokt.close(), 3000 );
+
+ }
+
+ }
+ };
+
+ // SOCEKT杩炴帴涓殑娑堟伅涓庣姸鎬佸搷搴�
+ function onOpen( e ) {
+ // 鍙戦�乯son
+ var chunk_size = new Array( 5, 10, 5 );
+ var request = {
+ "chunk_size": chunk_size,
+ "wav_name": "h5",
+ "is_speaking": true,
+ "chunk_interval":10,
+ };
+ speechSokt.send( JSON.stringify(request) );
+ console.log("杩炴帴鎴愬姛");
+ stateHandle(0);
+ }
+
+ function onClose( e ) {
+ stateHandle(1);
+ }
+
+ function onMessage( e ) {
+
+ msgHandle( e );
+ }
+
+ function onError( e ) {
+ info_div.innerHTML="杩炴帴"+e;
+ console.log(e);
+ stateHandle(2);
+ }
+
+
+}
\ No newline at end of file
--
Gitblit v1.9.1