From cfe1eb132a945848ab7e51ce35dbe3b4a8af0a93 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期三, 24 五月 2023 16:47:36 +0800
Subject: [PATCH] html5 docs
---
funasr/runtime/html5/ssl_key | 1
funasr/runtime/python/websocket/ssl_key | 1
funasr/runtime/ssl_key/readme_cn.md | 17 +++
funasr/runtime/ssl_key/server.key | 0
funasr/runtime/html5/readme.md | 108 +++++----------------
funasr/runtime/python/websocket/README.md | 4
funasr/runtime/ssl_key/server.crt | 0
funasr/runtime/python/websocket/parse_args.py | 4
funasr/runtime/html5/readme_cn.md | 128 +++++++++++++------------
funasr/runtime/ssl_key/readme.md | 17 +++
funasr/runtime/html5/h5Server.py | 4
11 files changed, 135 insertions(+), 149 deletions(-)
diff --git a/funasr/runtime/html5/h5Server.py b/funasr/runtime/html5/h5Server.py
index fa79430..d0ecf27 100644
--- a/funasr/runtime/html5/h5Server.py
+++ b/funasr/runtime/html5/h5Server.py
@@ -37,13 +37,13 @@
parser.add_argument("--certfile",
type=str,
- default="server.crt",
+ default="./ssl_key/server.crt",
required=False,
help="certfile for ssl")
parser.add_argument("--keyfile",
type=str,
- default="server.key",
+ default="./ssl_key/server.key",
required=False,
help="keyfile for ssl")
diff --git a/funasr/runtime/html5/readme.md b/funasr/runtime/html5/readme.md
index e60d588..a123216 100644
--- a/funasr/runtime/html5/readme.md
+++ b/funasr/runtime/html5/readme.md
@@ -1,107 +1,51 @@
-# online asr demo for html5
+# Html5 server for asr service
-## requirement
+## Requirement
### python
```shell
-flask
-gevent
-pyOpenSSL
+pip install flask
+# pip install gevent (Optional)
+# pip install pyOpenSSL (Optional)
```
-### javascript
+### javascript (Optional)
[html5 recorder.js](https://github.com/xiangyuecn/Recorder)
```shell
Recorder
```
-### demo
-
+## demo
+<div align="center"><img src="./demo.gif" width="150"/> </div>
-## wss or ws protocol for ws_server_online
-1) wss: browser microphone data --> html5 demo server --> js wss api --> wss asr online srv #for certificate generation just look back
-
-2) ws: browser microphone data --> html5 demo server --> js wss api --> nginx wss server --> ws asr online srv
-
-## 1.html5 demo start
-### ssl certificate is required
+## Steps
+### Html5 demo
```shell
-usage: h5Server.py [-h] [--host HOST] [--port PORT] [--certfile CERTFILE]
- [--keyfile KEYFILE]
-python h5Server.py --port 1337
+usage: h5Server.py [-h] [--host HOST] [--port PORT] [--certfile CERTFILE] [--keyfile KEYFILE]
```
-## 2.asr online srv start
-[detail for online asr](https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket)
-Online asr provides wss or ws way. if started in ws way, nginx is required for relay.
-### wss way, ssl certificate is required
+`e.g.`
```shell
-python ws_server_online.py --certfile server.crt --keyfile server.key --port 5921
+python h5Server.py --host 0.0.0.0 --port 1337
```
-### ws way
+### asr service
+[detail for asr]((../python/websocket))
+
+`Tips:` asr service and html5 service should be deployed on the same device.
```shell
-python ws_server_online.py --port 5921
+cd ../python/websocket
+python ws_server_online.py --port 1095
```
-## 3.open browser to access html5 demo
-https://youraddress:port/static/index.html
-## 4.modify asr address in html according to your environment
+### open browser to access html5 demo
+```shell
+https://127.0.0.1:1337/static/index.html
+# https://30.220.136.139:1337/static/index.html
+```
+
+### modify asr address in html according to your environment
asr address in index.html must be wss
-
-
-## certificate generation by yourself
-generated certificate may not suitable for all browsers due to security concerns. you'd better buy or download an authenticated ssl certificate from authorized agency.
-
-```shell
-### 1) Generate a private key
-openssl genrsa -des3 -out server.key 1024
-
-### 2) Generate a csr file
-openssl req -new -key server.key -out server.csr
-
-### 3) Remove pass
-cp server.key server.key.org
-openssl rsa -in server.key.org -out server.key
-
-### 4) Generated a crt file, valid for 1 year
-openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
-```
-
-## nginx configuration (you can skip it if you known)
-https and wss protocol are required by browsers when want to open microphone and websocket.
-if [online asr](https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket) run in ws way, you should use nginx to convert wss to ws.
-### nginx wss->ws configuration example
-```shell
-events { [0/1548]
- worker_connections 1024;
- accept_mutex on;
- }
-http {
- error_log error.log;
- access_log access.log;
- server {
-
- listen 5921 ssl http2; # nginx listen port for wss
- server_name www.test.com;
-
- ssl_certificate /funasr/server.crt;
- ssl_certificate_key /funasr/server.key;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_ciphers HIGH:!aNULL:!MD5;
-
- location /wss/ {
-
-
- proxy_pass http://127.0.0.1:1111/; # asr online model ws address and port
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_read_timeout 600s;
-
- }
- }
-```
## Acknowledge
1. This project is maintained by [FunASR community](https://github.com/alibaba-damo-academy/FunASR).
diff --git a/funasr/runtime/html5/readme_cn.md b/funasr/runtime/html5/readme_cn.md
index 5249d01..ac95029 100644
--- a/funasr/runtime/html5/readme_cn.md
+++ b/funasr/runtime/html5/readme_cn.md
@@ -17,37 +17,31 @@
## demo椤甸潰濡備笅
<div align="center"><img src="./demo.gif" width="150"/> </div>
-## 涓ょws_server杩炴帴妯″紡
-### 1)鐩存帴杩炴帴妯″紡锛屾祻瑙堝櫒https楹﹀厠椋� --> html5 demo鏈嶅姟 --> js wss鎺ュ彛 --> wss asr online srv(璇佷功鐢熸垚璇峰線鍚庣湅)
+[//]: # (## 涓ょws_server杩炴帴妯″紡)
-### 2)nginx涓浆锛屾祻瑙堝櫒https楹﹀厠椋� --> html5 demo鏈嶅姟 --> js wss鎺ュ彛 --> nginx鏈嶅姟 --> ws asr online srv
+[//]: # (### 1)鐩存帴杩炴帴妯″紡锛屾祻瑙堝櫒https楹﹀厠椋� --> html5 demo鏈嶅姟 --> js wss鎺ュ彛 --> wss asr online srv(璇佷功鐢熸垚璇峰線鍚庣湅))
+
+[//]: # (### 2)nginx涓浆锛屾祻瑙堝櫒https楹﹀厠椋� --> html5 demo鏈嶅姟 --> js wss鎺ュ彛 --> nginx鏈嶅姟 --> ws asr online srv)
## 鎿嶄綔姝ラ
### html5 demo鏈嶅姟鍚姩
-#### 鍚姩html5鏈嶅姟锛岄渶瑕乻sl璇佷功(宸茬敓鎴愶紝濡傞渶瑕佽嚜宸辩敓鎴愯寰�鍚庣湅)
-鐢ㄦ硶濡備笅:
+鍚姩html5鏈嶅姟锛岄渶瑕乻sl璇佷功(宸茬敓鎴愶紝濡傞渶瑕佽嚜宸辩敓鎴愯寰�鍚庣湅)
```shell
h5Server.py [-h] [--host HOST] [--port PORT] [--certfile CERTFILE] [--keyfile KEYFILE]
```
渚嬪瓙濡備笅锛岄渶瑕佹敞鎰廼p鍦板潃锛屽鏋滀粠鍏朵粬璁惧璁块棶闇�姹傦紙渚嬪鎵嬫満绔級锛岄渶瑕佸皢ip鍦板潃璁句负鐪熷疄ip
```shell
-python h5Server.py --host 0.0.0.0 --port 1337 --keyfile server.key
-# python h5Server.py --host 30.220.136.139 --port 1337 --keyfile server.key
+python h5Server.py --host 0.0.0.0 --port 1337
+# python h5Server.py --host 30.220.136.139 --port 1337
```
-### 鍚姩ws or wss asr online srv
+### 鍚姩ASR鏈嶅姟
[鍏蜂綋璇风湅online asr](../python/websocket)
-online asr鎻愪緵涓ょwss鍜寃s妯″紡锛寃ss妯″紡鍙互鐩存帴鍚姩锛屾棤闇�nginx涓浆銆傚惁鍒欓渶瑕侀�氳繃nginx灏唚ss杞彂鍒拌online asr鐨剋s绔彛涓�
`Tips:` asr 鏈嶅姟闇�瑕佷笌html5鏈嶅姟閮ㄧ讲鍒板悓涓�涓墿鐞嗘満鍣ㄤ笂
#### wss鏂瑰紡
```shell
cd ../python/websocket
-python ws_server_online.py --certfile ../../html5/server.crt --keyfile ../../html5/server.key --port 1095
-```
-#### ws鏂瑰紡
-```shell
-cd ../python/websocket
-python ws_server_online.py --port 1095
+python ws_server_online.py --port 1095
```
### 娴忚鍣ㄦ墦寮�鍦板潃
@@ -61,61 +55,73 @@
淇敼缃戦〉涓紝asr鏈嶅姟鍣ㄥ湴鍧�锛坵ebsocket srv鐨刬p涓庣鍙o級锛岀偣鍑诲紑濮嬪嵆鍙娇鐢ㄣ�傛敞鎰廻5鏈嶅姟鍜宎sr鏈嶅姟闇�瑕佸湪鍚屼竴涓湇鍔″櫒涓婏紝鍚﹀垯瀛樺湪璺ㄥ煙闂銆�
-## 鑷鐢熸垚璇佷功
-鐢熸垚璇佷功(娉ㄦ剰杩欑璇佷功骞朵笉鑳借鎵�鏈夋祻瑙堝櫒璁ゅ彲锛岄儴鍒嗘墜鍔ㄦ巿鏉冨彲浠ヨ闂�,鏈�濂戒娇鐢ㄥ叾浠栬璇佺殑瀹樻柟ssl璇佷功)
-```shell
-### 1)鐢熸垚绉侀挜锛屾寜鐓ф彁绀哄~鍐欏唴瀹�
-openssl genrsa -des3 -out server.key 1024
-
-### 2)鐢熸垚csr鏂囦欢 锛屾寜鐓ф彁绀哄~鍐欏唴瀹�
-openssl req -new -key server.key -out server.csr
-
-### 鍘绘帀pass
-cp server.key server.key.org
-openssl rsa -in server.key.org -out server.key
-
-### 鐢熸垚crt鏂囦欢锛屾湁鏁堟湡1骞达紙365澶╋級
-openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
-```
+[//]: # (## nginx閰嶇疆璇存槑(浜嗚В鐨勫彲浠ヨ烦杩�))
-## nginx閰嶇疆璇存槑(浜嗚В鐨勫彲浠ヨ烦杩�)
-h5鎵撳紑楹﹀厠椋庨渶瑕乭ttps鍗忚锛屽悓鏃跺悗绔殑asr websocket涔熷繀椤绘槸wss鍗忚锛屽鏋淸online asr](https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket)浠s鏂瑰紡杩愯锛屾垜浠彲浠ラ�氳繃nginx閰嶇疆瀹炵幇wss鍗忚鍒皐s鍗忚鐨勮浆鎹€��
+[//]: # (h5鎵撳紑楹﹀厠椋庨渶瑕乭ttps鍗忚锛屽悓鏃跺悗绔殑asr websocket涔熷繀椤绘槸wss鍗忚锛屽鏋淸online asr](https://github.com/alibaba-damo-academy/FunASR/tree/main/funasr/runtime/python/websocket)浠s鏂瑰紡杩愯锛屾垜浠彲浠ラ�氳繃nginx閰嶇疆瀹炵幇wss鍗忚鍒皐s鍗忚鐨勮浆鎹€��)
-### nginx杞彂閰嶇疆绀轰緥
-```shell
-events { [0/1548]
- worker_connections 1024;
- accept_mutex on;
- }
-http {
- error_log error.log;
- access_log access.log;
- server {
+[//]: # ()
+[//]: # (### nginx杞彂閰嶇疆绀轰緥)
- listen 5921 ssl http2; # nginx listen port for wss
- server_name www.test.com;
+[//]: # (```shell)
- ssl_certificate /funasr/server.crt;
- ssl_certificate_key /funasr/server.key;
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_ciphers HIGH:!aNULL:!MD5;
+[//]: # (events { [0/1548])
- location /wss/ {
+[//]: # ( worker_connections 1024;)
+[//]: # ( accept_mutex on;)
- proxy_pass http://127.0.0.1:1111/; # asr online model ws address and port
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- proxy_read_timeout 600s;
+[//]: # ( })
- }
- }
-```
-### 淇敼wsconnecter.js閲宎sr鎺ュ彛鍦板潃
-wsconnecter.js閲岄厤缃畂nline asr鏈嶅姟鍦板潃璺緞锛岃繖閲岄厤缃殑鏄痺ss绔彛
-var Uri = "wss://xxx:xxx/wss/"
+[//]: # (http {)
+
+[//]: # ( error_log error.log;)
+
+[//]: # ( access_log access.log;)
+
+[//]: # ( server {)
+
+[//]: # ()
+[//]: # ( listen 5921 ssl http2; # nginx listen port for wss)
+
+[//]: # ( server_name www.test.com;)
+
+[//]: # ()
+[//]: # ( ssl_certificate /funasr/server.crt;)
+
+[//]: # ( ssl_certificate_key /funasr/server.key;)
+
+[//]: # ( ssl_protocols TLSv1 TLSv1.1 TLSv1.2;)
+
+[//]: # ( ssl_ciphers HIGH:!aNULL:!MD5;)
+
+[//]: # ()
+[//]: # ( location /wss/ {)
+
+[//]: # ()
+[//]: # ()
+[//]: # ( proxy_pass http://127.0.0.1:1111/; # asr online model ws address and port)
+
+[//]: # ( proxy_http_version 1.1;)
+
+[//]: # ( proxy_set_header Upgrade $http_upgrade;)
+
+[//]: # ( proxy_set_header Connection "upgrade";)
+
+[//]: # ( proxy_read_timeout 600s;)
+
+[//]: # ()
+[//]: # ( })
+
+[//]: # ( })
+
+[//]: # (```)
+
+[//]: # (### 淇敼wsconnecter.js閲宎sr鎺ュ彛鍦板潃)
+
+[//]: # (wsconnecter.js閲岄厤缃畂nline asr鏈嶅姟鍦板潃璺緞锛岃繖閲岄厤缃殑鏄痺ss绔彛)
+
+[//]: # (var Uri = "wss://xxx:xxx/wss/" )
## Acknowledge
1. This project is maintained by [FunASR community](https://github.com/alibaba-damo-academy/FunASR).
2. We acknowledge [AiHealthx](http://www.aihealthx.com/) for contributing the html5 demo.
\ No newline at end of file
diff --git a/funasr/runtime/html5/ssl_key b/funasr/runtime/html5/ssl_key
new file mode 120000
index 0000000..1c9e2c0
--- /dev/null
+++ b/funasr/runtime/html5/ssl_key
@@ -0,0 +1 @@
+../ssl_key
\ No newline at end of file
diff --git a/funasr/runtime/python/websocket/README.md b/funasr/runtime/python/websocket/README.md
index f7c3cc7..f489bac 100644
--- a/funasr/runtime/python/websocket/README.md
+++ b/funasr/runtime/python/websocket/README.md
@@ -35,7 +35,7 @@
```
##### Usage examples
```shell
-python ws_server_offline.py --port 10095 --asr_model "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" --certfile ./server.crt --keyfile ./server.key
+python ws_server_offline.py --port 10095 --asr_model "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch"
```
#### ASR streaming server
@@ -51,7 +51,7 @@
```
##### Usage examples
```shell
-python ws_server_online.py --port 10095 --asr_model_online "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online" --certfile ./server.crt --keyfile ./server.key
+python ws_server_online.py --port 10095 --asr_model_online "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online"
```
#### ASR offline/online 2pass server
diff --git a/funasr/runtime/python/websocket/parse_args.py b/funasr/runtime/python/websocket/parse_args.py
index bfa5a87..82d9c90 100644
--- a/funasr/runtime/python/websocket/parse_args.py
+++ b/funasr/runtime/python/websocket/parse_args.py
@@ -37,13 +37,13 @@
help="cpu cores")
parser.add_argument("--certfile",
type=str,
- default="",
+ default="./ssl_key/server.crt",
required=False,
help="certfile for ssl")
parser.add_argument("--keyfile",
type=str,
- default="",
+ default="./ssl_key/server.key",
required=False,
help="keyfile for ssl")
args = parser.parse_args()
diff --git a/funasr/runtime/python/websocket/ssl_key b/funasr/runtime/python/websocket/ssl_key
new file mode 120000
index 0000000..e5d59f1
--- /dev/null
+++ b/funasr/runtime/python/websocket/ssl_key
@@ -0,0 +1 @@
+../../ssl_key
\ No newline at end of file
diff --git a/funasr/runtime/ssl_key/readme.md b/funasr/runtime/ssl_key/readme.md
new file mode 100644
index 0000000..a5989e6
--- /dev/null
+++ b/funasr/runtime/ssl_key/readme.md
@@ -0,0 +1,17 @@
+## certificate generation by yourself
+generated certificate may not suitable for all browsers due to security concerns. you'd better buy or download an authenticated ssl certificate from authorized agency.
+
+```shell
+### 1) Generate a private key
+openssl genrsa -des3 -out server.key 1024
+
+### 2) Generate a csr file
+openssl req -new -key server.key -out server.csr
+
+### 3) Remove pass
+cp server.key server.key.org
+openssl rsa -in server.key.org -out server.key
+
+### 4) Generated a crt file, valid for 1 year
+openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
+```
\ No newline at end of file
diff --git a/funasr/runtime/ssl_key/readme_cn.md b/funasr/runtime/ssl_key/readme_cn.md
new file mode 100644
index 0000000..eeadef4
--- /dev/null
+++ b/funasr/runtime/ssl_key/readme_cn.md
@@ -0,0 +1,17 @@
+## 鑷鐢熸垚璇佷功
+鐢熸垚璇佷功(娉ㄦ剰杩欑璇佷功骞朵笉鑳借鎵�鏈夋祻瑙堝櫒璁ゅ彲锛岄儴鍒嗘墜鍔ㄦ巿鏉冨彲浠ヨ闂�,鏈�濂戒娇鐢ㄥ叾浠栬璇佺殑瀹樻柟ssl璇佷功)
+
+```shell
+### 1)鐢熸垚绉侀挜锛屾寜鐓ф彁绀哄~鍐欏唴瀹�
+openssl genrsa -des3 -out server.key 1024
+
+### 2)鐢熸垚csr鏂囦欢 锛屾寜鐓ф彁绀哄~鍐欏唴瀹�
+openssl req -new -key server.key -out server.csr
+
+### 鍘绘帀pass
+cp server.key server.key.org
+openssl rsa -in server.key.org -out server.key
+
+### 鐢熸垚crt鏂囦欢锛屾湁鏁堟湡1骞达紙365澶╋級
+openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
+```
diff --git a/funasr/runtime/html5/server.crt b/funasr/runtime/ssl_key/server.crt
similarity index 100%
rename from funasr/runtime/html5/server.crt
rename to funasr/runtime/ssl_key/server.crt
diff --git a/funasr/runtime/html5/server.key b/funasr/runtime/ssl_key/server.key
similarity index 100%
rename from funasr/runtime/html5/server.key
rename to funasr/runtime/ssl_key/server.key
--
Gitblit v1.9.1