From a31e878c0e1ca4699a1e96aa01617125be6b6ccb Mon Sep 17 00:00:00 2001 From: 游雁 <zhifu.gzf@alibaba-inc.com> Date: 星期四, 29 六月 2023 15:56:36 +0800 Subject: [PATCH] dcos --- funasr/runtime/readme_cn.md | 10 + funasr/runtime/SDK_tutorial.md | 327 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 337 insertions(+), 0 deletions(-) diff --git a/funasr/runtime/SDK_tutorial.md b/funasr/runtime/SDK_tutorial.md new file mode 100644 index 0000000..77508c9 --- /dev/null +++ b/funasr/runtime/SDK_tutorial.md @@ -0,0 +1,327 @@ +# FunASR绂荤嚎鏂囦欢杞啓鏈嶅姟涓�閿儴缃叉暀绋� + +FunASR鎻愪緵鍙竴閿湰鍦版垨鑰呬簯绔湇鍔″櫒閮ㄧ讲鐨勭绾挎枃浠惰浆鍐欐湇鍔★紝鍐呮牳涓篎unASR宸插紑婧恟untime-SDK銆傞泦鎴愪簡杈炬懇闄㈣闊冲疄楠屽鍦∕odelscope绀惧尯寮�婧愮殑璇煶绔偣妫�娴�(VAD)銆丳araformer-large璇煶璇嗗埆(ASR)銆佹爣鐐规仮澶�(PUNC) 绛夌浉鍏宠兘鍔涳紝鍙互鍑嗙‘銆侀珮鏁堢殑瀵归煶棰戣繘琛岄珮骞跺彂杞啓銆� + +## 鐜瀹夎涓庡惎鍔ㄦ湇鍔� + +### 鑾峰緱鑴氭湰宸ュ叿骞朵竴閿儴缃� + +閫氳繃浠ヤ笅鍛戒护杩愯涓�閿儴缃叉湇鍔★紝鎸夌収鎻愮ず閫愭瀹屾垚FunASR runtime-SDK鏈嶅姟鐨勯儴缃插拰杩愯銆傜洰鍓嶆殏鏃朵粎鏀寔Linux鐜锛屽叾浠栫幆澧冨弬鑰冩枃妗楂橀樁寮�鍙戞寚鍗梋()銆� +鍙楅檺浜庣綉缁滐紝funasr-runtime-deploy.sh涓�閿儴缃插伐鍏风殑涓嬭浇鍙兘涓嶉『鍒╋紝閬囧埌鏁扮杩樻湭涓嬭浇杩涘叆涓�閿儴缃插伐鍏风殑鎯呭喌锛岃Ctrl + C 缁堟鍚庡啀娆¤繍琛屼互涓嬪懡浠ゃ�� + +```shell +curl -O https://raw.githubusercontent.com/alibaba-damo-academy/FunASR-APP/main/TransAudio/funasr-runtime-deploy.sh ; sudo bash funasr-runtime-deploy.sh install +``` + +#### 鍚姩杩囩▼閰嶇疆璇﹁В + +##### 閫夋嫨FunASR Docker闀滃儚 +鎺ㄨ崘閫夋嫨latest浣跨敤鎴戜滑鐨勬渶鏂伴暅鍍忥紝涔熷彲閫夋嫨鍘嗗彶鐗堟湰銆� +```text +[1/10] + Please choose the Docker image. + 1) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest + 2) registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.0.1 + Enter your choice: 1 + You have chosen the Docker image: registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest +``` + +##### 閫夋嫨ASR/VAD/PUNC妯″瀷 + +浣犲彲浠ラ�夋嫨ModelScope涓殑妯″瀷锛屼篃鍙互閫�<model_name>鑷濉叆ModelScope涓殑妯″瀷鍚嶏紝灏嗕細鍦―ocker杩愯鏃惰嚜鍔ㄤ笅杞姐�傚悓鏃朵篃鍙互閫夋嫨<model_path>濉叆瀹夸富鏈轰腑鐨勬湰鍦版ā鍨嬭矾寰勩�� + +```text +[2/10] + Please input [y/n] to confirm whether to automatically download model_id in ModelScope or use a local model. + [y] With the model in ModelScope, the model will be automatically downloaded to Docker(/workspace/models). + [n] Use the models on the localhost, the directory where the model is located will be mapped to Docker. + Setting confirmation[y/n]: + You have chosen to use the model in ModelScope, please set the model ID in the next steps, and the model will be automatically downloaded during the run. + + [2.1/10] + Please select ASR model_id in ModelScope from the list below. + 1) damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx + 2) model_name + 3) model_path + Enter your choice: 1 + The model ID is damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx + The model dir in Docker is /workspace/models/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx + + [2.2/10] + Please select VAD model_id in ModelScope from the list below. + 1) damo/speech_fsmn_vad_zh-cn-16k-common-onnx + 2) model_name + 3) model_path + Enter your choice: 1 + The model ID is damo/speech_fsmn_vad_zh-cn-16k-common-onnx + The model dir in Docker is /workspace/models/speech_fsmn_vad_zh-cn-16k-common-onnx + + [2.3/10] + Please select PUNC model_id in ModelScope from the list below. + 1) damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx + 2) model_name + 3) model_path + Enter your choice: 1 + The model ID is damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx + The model dir in Docker is /workspace/models/punc_ct-transformer_zh-cn-common-vocab272727-onnx +``` + +##### 杈撳叆瀹夸富鏈轰腑FunASR鏈嶅姟鍙墽琛岀▼搴忚矾寰� + +杈撳叆FunASR鏈嶅姟鍙墽琛岀▼搴忕殑瀹夸富鏈鸿矾寰勶紝Docker杩愯鏃跺皢鑷姩鎸傝浇鍒癉ocker涓繍琛屻�傞粯璁や笉杈撳叆鐨勬儏鍐典笅灏嗘寚瀹欴ocker涓粯璁ょ殑/workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server銆� + +```text +[3/10] + Please enter the path to the excutor of the FunASR service on the localhost. + If not set, the default /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server in Docker is used. + Setting the path to the excutor of the FunASR service on the localhost: + Corresponding, the path of FunASR in Docker is /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server +``` + +##### 璁剧疆瀹夸富鏈烘彁渚涚粰FunASR鐨勭鍙� +璁剧疆鎻愪緵缁橠ocker鐨勫涓绘満绔彛锛岄粯璁や负10095銆傝淇濊瘉姝ょ鍙e彲鐢ㄣ�� +```text +[4/10] + Please input the opened port in the host used for FunASR server. + Default: 10095 + Setting the opened host port [1-65535]: + The port of the host is 10095 +``` + +##### 璁剧疆Docker涓彁渚涚粰FunASR鐨勭鍙� +璁剧疆Docker涓璅unASR鏈嶅姟浣跨敤鐨勭鍙o紝榛樿涓�10095锛屾绔彛灏嗕簬step1.4涓缃殑瀹夸富鏈虹鍙h繘琛屾槧灏勩�� +```text +5/10] + Please input port for docker mapped. + Default: 10095, the opened port of current host is 10095 + Setting the port in Docker for FunASR server [1-65535]: + The port in Docker for FunASR server is 10095 +``` + +##### 璁剧疆FunASR鏈嶅姟鐨勬帹鐞嗙嚎绋嬫暟 +璁剧疆FunASR鏈嶅姟鐨勬帹鐞嗙嚎绋嬫暟锛岄粯璁や负瀹夸富鏈烘牳鏁帮紝鍚屾椂鑷姩璁剧疆鏈嶅姟鐨処O绾跨▼鏁帮紝涓烘帹鐞嗙嚎绋嬫暟鐨勫洓鍒嗕箣涓�銆� +```text +[6/10] + Please input thread number for FunASR decoder. + Default: 1 + Setting the number of decoder thread: + + The number of decoder threads is 1 + The number of IO threads is 1 +``` + +##### 鎵�鏈夎缃弬鏁板睍绀哄強纭 + +灞曠ず鍓嶉潰6姝ヨ缃殑鍙傛暟锛岀‘璁ゅ垯灏嗘墍鏈夊弬鏁板瓨鍌ㄥ埌/var/funasr/config锛屽苟寮�濮嬪惎鍔―ocker锛屽惁鍒欐彁绀虹敤鎴疯繘琛岄噸鏂拌缃�� + +```text +[7/10] + Show parameters of FunASR server setting and confirm to run ... + + The current Docker image is : registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest + The model will be automatically downloaded to the directory : /workspace/models + The ASR model_id used : damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx + The ASR model directory corresponds to the directory in Docker : /workspace/models/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx + The VAD model_id used : damo/speech_fsmn_vad_zh-cn-16k-common-onnx + The VAD model directory corresponds to the directory in Docker : /workspace/models/speech_fsmn_vad_zh-cn-16k-common-onnx + The PUNC model_id used : damo/punc_ct-transformer_zh-cn-common-vocab272727-onnx + The PUNC model directory corresponds to the directory in Docker: /workspace/models/punc_ct-transformer_zh-cn-common-vocab272727-onnx + + The path in the docker of the FunASR service executor : /workspace/FunASR/funasr/runtime/websocket/build/bin/funasr-wss-server + Set the host port used for use by the FunASR service : 10095 + Set the docker port used by the FunASR service : 10095 + Set the number of threads used for decoding the FunASR service : 1 + Set the number of threads used for IO the FunASR service : 1 + + Please input [y/n] to confirm the parameters. + [y] Verify that these parameters are correct and that the service will run. + [n] The parameters set are incorrect, it will be rolled out, please rerun. + read confirmation[y/n]: + + Will run FunASR server later ... + Parameters are stored in the file /var/funasr/config +``` + +##### 妫�鏌ocker鏈嶅姟 + +妫�鏌ュ綋鍓嶅涓绘満鏄惁瀹夎浜咲ocker鏈嶅姟锛岃嫢鏈畨瑁咃紝鍒欏畨瑁匘ocker骞跺惎鍔ㄣ�� + +```text +[8/10] + Start install docker for ubuntu + Get docker installer: curl -fsSL https://test.docker.com -o test-docker.sh + Get docker run: sudo sh test-docker.sh +# Executing docker install script, commit: c2de0811708b6d9015ed1a2c80f02c9b70c8ce7b ++ sh -c apt-get update -qq >/dev/null ++ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null ++ sh -c install -m 0755 -d /etc/apt/keyrings ++ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg ++ sh -c chmod a+r /etc/apt/keyrings/docker.gpg ++ sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal test" > /etc/apt/sources.list.d/docker.list ++ sh -c apt-get update -qq >/dev/null ++ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null ++ sh -c docker version +Client: Docker Engine - Community + Version: 24.0.2 + + ... + ... + + Docker install success, start docker server. +``` + +##### 涓嬭浇FunASR Docker闀滃儚 + +涓嬭浇骞舵洿鏂皊tep1.1涓�夋嫨鐨凢unASR Docker闀滃儚銆� + +```text +[9/10] + Pull docker image(registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-latest)... +funasr-runtime-cpu-0.0.1: Pulling from funasr_repo/funasr +7608715873ec: Pull complete +3e1014c56f38: Pull complete + + ... + ... +``` + +##### 鍚姩FunASR Docker + +鍚姩FunASR Docker锛岀瓑寰卻tep1.2閫夋嫨鐨勬ā鍨嬩笅杞藉畬鎴愬苟鍚姩FunASR鏈嶅姟銆� + +```text +[10/10] + Construct command and run docker ... +943d8f02b4e5011b71953a0f6c1c1b9bc5aff63e5a96e7406c83e80943b23474 + + Loading models: + [ASR ][Done ][==================================================][100%][1.10MB/s][v1.2.1] + [VAD ][Done ][==================================================][100%][7.26MB/s][v1.2.0] + [PUNC][Done ][==================================================][100%][ 474kB/s][v1.1.7] + The service has been started. + If you want to see an example of how to use the client, you can run sudo bash funasr-runtime-deploy.sh -c . +``` + +#### 鍚姩宸茬粡閮ㄧ讲杩囩殑FunASR鏈嶅姟 +涓�閿儴缃插悗鑻ュ嚭鐜伴噸鍚數鑴戠瓑鍏抽棴Docker鐨勫姩浣滐紝鍙�氳繃濡備笅鍛戒护鐩存帴鍚姩FunASR鏈嶅姟锛屽惎鍔ㄩ厤缃负涓婃涓�閿儴缃茬殑璁剧疆銆� + +```shell +sudo bash funasr-runtime-deploy.sh start +``` + +#### 鍏抽棴FunASR鏈嶅姟 + +```shell +sudo bash funasr-runtime-deploy.sh stop +``` + +#### 閲嶅惎FunASR鏈嶅姟 + +鏍规嵁涓婃涓�閿儴缃茬殑璁剧疆閲嶅惎鍚姩FunASR鏈嶅姟銆� +```shell +sudo bash funasr-runtime-deploy.sh restart +``` + +#### 鏇挎崲妯″瀷骞堕噸鍚疐unASR鏈嶅姟 + +鏇挎崲姝e湪浣跨敤鐨勬ā鍨嬶紝骞堕噸鏂板惎鍔‵unASR鏈嶅姟銆傛ā鍨嬮渶涓篗odelScope涓殑ASR/VAD/PUNC妯″瀷銆� + +```shell +sudo bash scripts/funasr-runtime-deploy.sh update model <model ID in ModelScope> + +e.g +sudo bash scripts/funasr-runtime-deploy.sh update model damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-onnx +``` + +### 娴嬭瘯涓庝娇鐢ㄧ绾挎枃浠惰浆鍐欐湇鍔� + +鍦ㄦ湇鍔″櫒涓婂畬鎴怓unASR鏈嶅姟閮ㄧ讲浠ュ悗锛屽彲浠ラ�氳繃濡備笅鐨勬楠ゆ潵娴嬭瘯鍜屼娇鐢ㄧ绾挎枃浠惰浆鍐欐湇鍔°�傜洰鍓嶅垎鍒敮鎸丳ython銆丆++銆丣ava鐗堟湰client鐨勭殑鍛戒护琛岃繍琛岋紝浠ュ強鍙湪娴忚鍣ㄥ彲鐩存帴浣撻獙鐨刪tml缃戦〉鐗堟湰锛屾洿澶氳瑷�client鏀寔鍙傝�冩枃妗c�怓unASR楂橀樁寮�鍙戞寚鍗椼�戙�� +funasr-runtime-deploy.sh杩愯缁撴潫鍚庯紝鍙�氳繃鍛戒护浠ヤ氦浜掔殑褰㈠紡鑷姩涓嬭浇娴嬭瘯鏍蜂緥samples鍒板綋鍓嶇洰褰曠殑funasr_samples涓紝骞惰缃弬鏁拌繍琛岋細 + +```shell +sudo bash funasr-runtime-deploy.sh client +``` + +鍙�夋嫨鎻愪緵鐨凱ython鍜孡inux C++鑼冧緥绋嬪簭锛屼互Python鑼冧緥涓轰緥锛� + +```text +Will download sample tools for the client to show how speech recognition works. + Please select the client you want to run. + 1) Python + 2) Linux_Cpp + Enter your choice: 1 + + Please enter the IP of server, default(127.0.0.1): + Please enter the port of server, default(10095): + Please enter the audio path, default(/root/funasr_samples/audio/asr_example.wav): + + Run pip3 install click>=8.0.4 +Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/ +Requirement already satisfied: click>=8.0.4 in /usr/local/lib/python3.8/dist-packages (8.1.3) + + Run pip3 install -r /root/funasr_samples/python/requirements_client.txt +Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/ +Requirement already satisfied: websockets in /usr/local/lib/python3.8/dist-packages (from -r /root/funasr_samples/python/requirements_client.txt (line 1)) (11.0.3) + + Run python3 /root/funasr_samples/python/wss_client_asr.py --host 127.0.0.1 --port 10095 --mode offline --audio_in /root/funasr_samples/audio/asr_example.wav --send_without_sleep --output_dir ./funasr_samples/python + + ... + ... + + pid0_0: 娆㈣繋澶у鏉ヤ綋楠岃揪鎽╅櫌鎺ㄥ嚭鐨勮闊宠瘑鍒ā鍨嬨�� +Exception: sent 1000 (OK); then received 1000 (OK) +end + + If failed, you can try (python3 /root/funasr_samples/python/wss_client_asr.py --host 127.0.0.1 --port 10095 --mode offline --audio_in /root/funasr_samples/audio/asr_example.wav --send_without_sleep --output_dir ./funasr_samples/python) in your Shell. + +``` + +#### python-client +鑻ユ兂鐩存帴杩愯client杩涜娴嬭瘯锛屽彲鍙傝�冨涓嬬畝鏄撹鏄庯紝浠ython鐗堟湰涓轰緥锛� + +```shell +python3 wss_client_asr.py --host "127.0.0.1" --port 10095 --mode offline --audio_in "../audio/asr_example.wav" --send_without_sleep --output_dir "./results" +``` + +鍛戒护鍙傛暟璇存槑锛� +```text +--host 涓篎unASR runtime-SDK鏈嶅姟閮ㄧ讲鏈哄櫒ip锛岄粯璁や负鏈満ip锛�127.0.0.1锛夛紝濡傛灉client涓庢湇鍔′笉鍦ㄥ悓涓�鍙版湇鍔″櫒锛岄渶瑕佹敼涓洪儴缃叉満鍣╥p +--port 10095 閮ㄧ讲绔彛鍙� +--mode offline琛ㄧず绂荤嚎鏂囦欢杞啓 +--audio_in 闇�瑕佽繘琛岃浆鍐欑殑闊抽鏂囦欢锛屾敮鎸佹枃浠惰矾寰勶紝鏂囦欢鍒楄〃wav.scp +--output_dir 璇嗗埆缁撴灉淇濆瓨璺緞 +``` + +#### cpp-client + +```shell +export LD_LIBRARY_PATH=/root/funasr_samples/cpp/libs:$LD_LIBRARY_PATH +/root/funasr_samples/cpp/funasr-wss-client --server-ip 127.0.0.1 --port 10095 --wav-path /root/funasr_samples/audio/asr_example.wav +``` + +鍛戒护鍙傛暟璇存槑锛� + +```text +--server-ip 涓篎unASR runtime-SDK鏈嶅姟閮ㄧ讲鏈哄櫒ip锛岄粯璁や负鏈満ip锛�127.0.0.1锛夛紝濡傛灉client涓庢湇鍔′笉鍦ㄥ悓涓�鍙版湇鍔″櫒锛岄渶瑕佹敼涓洪儴缃叉満鍣╥p +--port 10095 閮ㄧ讲绔彛鍙� +--wav-path 闇�瑕佽繘琛岃浆鍐欑殑闊抽鏂囦欢锛屾敮鎸佹枃浠惰矾寰� +``` + +### 瑙嗛demo + +[鐐瑰嚮姝ゅ]() + + + + + + + + + + + + + + + diff --git a/funasr/runtime/readme_cn.md b/funasr/runtime/readme_cn.md new file mode 100644 index 0000000..52bee72 --- /dev/null +++ b/funasr/runtime/readme_cn.md @@ -0,0 +1,10 @@ +# FunASR runtime-SDK +FunASR鏄敱杈炬懇闄㈣闊冲疄楠屽寮�婧愮殑涓�娆捐闊宠瘑鍒熀纭�妗嗘灦锛岄泦鎴愪簡璇煶绔偣妫�娴嬨�佽闊宠瘑鍒�佹爣鐐规柇鍙ョ瓑棰嗗煙鐨勫伐涓氱骇鍒ā鍨嬶紝鍚稿紩浜嗕紬澶氬紑鍙戣�呭弬涓庝綋楠屽拰寮�鍙戙�備负浜嗚В鍐冲伐涓氳惤鍦扮殑鏈�鍚庝竴鍏噷锛屽皢妯″瀷闆嗘垚鍒颁笟鍔′腑鍘伙紝鎴戜滑寮�鍙戜簡FunASR runtime-SDK銆傝SDK宸叉敮鎸佽闊崇绾挎枃浠舵湇鍔¢儴缃诧紝鎷ユ湁瀹屾暣鐨勮闊宠瘑鍒摼璺紝鍙互灏嗗嚑鍗佷釜灏忔椂鐨勯煶棰戣瘑鍒垚甯︽爣鐐圭殑鏂囧瓧锛岃�屼笖鏀寔涓婄櫨璺苟鍙戝悓鏃惰繘琛岃瘑鍒�� + +涓轰簡鏀寔涓嶅悓鐢ㄦ埛鐨勯渶姹傦紝鎴戜滑鍒嗗埆閽堝灏忕櫧涓庨珮闃跺紑鍙戣�咃紝鍑嗗浜嗕笉鍚岀殑鍥炬枃鏁欑▼锛� + +## Runtime-SDK 涓�閿儴缃叉暀绋� +璇ユ暀绋嬩富瑕侀拡瀵瑰皬鐧界敤鎴凤紝鏃犱慨鏀瑰畾鍒堕渶姹傦紝鏀寔浠巑odelscope涓笅杞芥ā鍨嬮儴缃诧紝涔熸敮鎸佺敤鎴穎inetune鍚庣殑妯″瀷閮ㄧ讲锛岃缁嗘暀绋嬪弬鑰冿紙[鐐瑰嚮姝ゅ](./SDK_tutorial.md)锛� + +## Runtime-SDK 楂橀樁寮�鍙戞寚鍗� +璇ユ暀绋嬩富瑕侀拡瀵归珮闃跺紑鍙戣�咃紝闇�瑕佸鏈嶅姟杩涜淇敼涓庡畾鍒讹紝鏀寔浠巑odelscope涓笅杞芥ā鍨嬮儴缃诧紝涔熸敮鎸佺敤鎴穎inetune鍚庣殑妯″瀷閮ㄧ讲锛岃缁嗘暀绋嬪弬鑰冿紙[鐐瑰嚮姝ゅ]()锛� -- Gitblit v1.9.1