From 720c048410981bf33dad02091552118ecda9e31d Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期二, 13 六月 2023 19:40:06 +0800
Subject: [PATCH] Merge branch 'main' of https://github.com/alibaba-damo-academy/FunASR into main
---
funasr/bin/asr_infer.py | 4 +-
funasr/version.txt | 2
funasr/runtime/python/websocket/wss_srv_asr.py | 6 +-
funasr/models/e2e_vad.py | 15 ++++---
funasr/runtime/html5/readme.md | 2
funasr/runtime/html5/static/index.html | 3 +
funasr/runtime/python/websocket/parse_args.py | 2
funasr/runtime/html5/readme_cn.md | 2
funasr/runtime/html5/static/main.js | 47 ++++++++++++++++-------
9 files changed, 52 insertions(+), 31 deletions(-)
diff --git a/funasr/bin/asr_infer.py b/funasr/bin/asr_infer.py
index 0e203c4..47ce0ee 100644
--- a/funasr/bin/asr_infer.py
+++ b/funasr/bin/asr_infer.py
@@ -493,9 +493,9 @@
else:
if pre_token_length[i] == 0:
yseq = torch.tensor(
- [self.asr_model.sos] + [self.asr_model.eos], device=yseq.device
+ [self.asr_model.sos] + [self.asr_model.eos], device=pre_acoustic_embeds.device
)
- score = torch.tensor(0.0, device=yseq.device)
+ score = torch.tensor(0.0, device=pre_acoustic_embeds.device)
else:
yseq = am_scores.argmax(dim=-1)
score = am_scores.max(dim=-1)[0]
diff --git a/funasr/models/e2e_vad.py b/funasr/models/e2e_vad.py
index 846341d..14d56a8 100644
--- a/funasr/models/e2e_vad.py
+++ b/funasr/models/e2e_vad.py
@@ -296,13 +296,14 @@
self.sil_frame = 0
self.frame_probs = []
- assert self.output_data_buf[-1].contain_seg_end_point == True
- drop_frames = int(self.output_data_buf[-1].end_ms / self.vad_opts.frame_in_ms)
- real_drop_frames = drop_frames - self.last_drop_frames
- self.last_drop_frames = drop_frames
- self.data_buf_all = self.data_buf_all[real_drop_frames * int(self.vad_opts.frame_in_ms * self.vad_opts.sample_rate / 1000):]
- self.decibel = self.decibel[real_drop_frames:]
- self.scores = self.scores[:, real_drop_frames:, :]
+ if self.output_data_buf:
+ assert self.output_data_buf[-1].contain_seg_end_point == True
+ drop_frames = int(self.output_data_buf[-1].end_ms / self.vad_opts.frame_in_ms)
+ real_drop_frames = drop_frames - self.last_drop_frames
+ self.last_drop_frames = drop_frames
+ self.data_buf_all = self.data_buf_all[real_drop_frames * int(self.vad_opts.frame_in_ms * self.vad_opts.sample_rate / 1000):]
+ self.decibel = self.decibel[real_drop_frames:]
+ self.scores = self.scores[:, real_drop_frames:, :]
def ComputeDecibel(self) -> None:
frame_sample_length = int(self.vad_opts.frame_length_ms * self.vad_opts.sample_rate / 1000)
diff --git a/funasr/runtime/html5/readme.md b/funasr/runtime/html5/readme.md
index 930aa88..1e9031e 100644
--- a/funasr/runtime/html5/readme.md
+++ b/funasr/runtime/html5/readme.md
@@ -41,7 +41,7 @@
`Tips:` asr service and html5 service should be deployed on the same device.
```shell
cd ../python/websocket
-python wss_srv_asr.py --port 1095
+python wss_srv_asr.py --port 10095
```
diff --git a/funasr/runtime/html5/readme_cn.md b/funasr/runtime/html5/readme_cn.md
index 73bf1b0..b859387 100644
--- a/funasr/runtime/html5/readme_cn.md
+++ b/funasr/runtime/html5/readme_cn.md
@@ -49,7 +49,7 @@
#### wss鏂瑰紡
```shell
cd ../python/websocket
-python wss_srv_asr.py --port 1095
+python wss_srv_asr.py --port 10095
```
### 娴忚鍣ㄦ墦寮�鍦板潃
diff --git a/funasr/runtime/html5/static/index.html b/funasr/runtime/html5/static/index.html
index b99a140..99aa9b4 100644
--- a/funasr/runtime/html5/static/index.html
+++ b/funasr/runtime/html5/static/index.html
@@ -19,7 +19,7 @@
<div class="div_class_recordControl">
asr鏈嶅姟鍣ㄥ湴鍧�(蹇呭~):
<br>
- <input id="wssip" type="text" style=" width: 100%;height:100%" value="wss://127.0.0.1:1095/"/>
+ <input id="wssip" type="text" style=" width: 100%;height:100%" value="wss://127.0.0.1:10095/"/>
<br>
<br>
<div style="border:2px solid #ccc;">
@@ -36,6 +36,7 @@
<br>
<div id="info_div">璇风偣鍑诲紑濮�</div>
<div class="div_class_buttons">
+ <button id="btnConnect">杩炴帴</button>
<button id="btnStart">寮�濮�</button>
<button id="btnStop">鍋滄</button>
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 9317778..22f53c1 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -23,12 +23,14 @@
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 offline_text="";
@@ -38,7 +40,7 @@
//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;
@@ -64,16 +66,18 @@
var asrmodel=JSON.parse(jsonMsg.data)['mode'];
if(asrmodel=="2pass-offline")
{
- offline_text=offline_text+rectxt.replace(/ +/g,"");
+ offline_text=offline_text+rectxt; //.replace(/ +/g,"");
rec_text=offline_text;
}
else
{
- rec_text=rec_text+rectxt.replace(/ +/g,"");
+ rec_text=rec_text+rectxt; //.replace(/ +/g,"");
}
var varArea=document.getElementById('varArea');
varArea.value=rec_text;
+ console.log( "offline_text: " + asrmodel+","+offline_text);
+ console.log( "rec_text: " + rec_text);
}
@@ -82,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 ) {
@@ -95,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() {
@@ -107,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;
+
}
}
@@ -147,7 +163,10 @@
btnStop.disabled = true;
setTimeout(function(){
console.log("call stop ws!");
- wsconnecter.wsStop();btnStart.disabled = false;info_div.innerHTML="璇风偣鍑诲紑濮�";}, 3000 );
+ wsconnecter.wsStop();
+ btnStart.disabled = true;
+ btnConnect.disabled=false;
+ info_div.innerHTML="璇风偣鍑昏繛鎺�";}, 3000 );
rec.stop(function(blob,duration){
console.log(blob);
diff --git a/funasr/runtime/python/websocket/parse_args.py b/funasr/runtime/python/websocket/parse_args.py
index 82d9c90..ffecff7 100644
--- a/funasr/runtime/python/websocket/parse_args.py
+++ b/funasr/runtime/python/websocket/parse_args.py
@@ -33,7 +33,7 @@
help="0 for cpu, 1 for gpu")
parser.add_argument("--ncpu",
type=int,
- default=1,
+ default=4,
help="cpu cores")
parser.add_argument("--certfile",
type=str,
diff --git a/funasr/runtime/python/websocket/wss_srv_asr.py b/funasr/runtime/python/websocket/wss_srv_asr.py
index 75be08c..09f2305 100644
--- a/funasr/runtime/python/websocket/wss_srv_asr.py
+++ b/funasr/runtime/python/websocket/wss_srv_asr.py
@@ -67,9 +67,9 @@
websocket.param_dict_asr_online = {"cache": dict()}
websocket.param_dict_vad = {'in_cache': dict(), "is_final": True}
websocket.param_dict_asr_online["is_final"]=True
- audio_in=b''.join(np.zeros(int(16000),dtype=np.int16))
- inference_pipeline_vad(audio_in=audio_in, param_dict=websocket.param_dict_vad)
- inference_pipeline_asr_online(audio_in=audio_in, param_dict=websocket.param_dict_asr_online)
+ # audio_in=b''.join(np.zeros(int(16000),dtype=np.int16))
+ # inference_pipeline_vad(audio_in=audio_in, param_dict=websocket.param_dict_vad)
+ # inference_pipeline_asr_online(audio_in=audio_in, param_dict=websocket.param_dict_asr_online)
await websocket.close()
diff --git a/funasr/version.txt b/funasr/version.txt
index 659914a..ee6cdce 100644
--- a/funasr/version.txt
+++ b/funasr/version.txt
@@ -1 +1 @@
-0.5.8
+0.6.1
--
Gitblit v1.9.1