Skip to content

Commit

Permalink
python-websocket funasr1.0 (#1310)
Browse files Browse the repository at this point in the history
* fix add_file bug (#1296)

Co-authored-by: shixian.shi <[email protected]>

* funasr1.0 uniasr

* funasr1.0 uniasr

* update with main (#1305)

* v1.0.3

* update clients for 2pass

* update download tools

---------

Co-authored-by: 雾聪 <[email protected]>

* vad streaming return [beg, -1], [], [-1, end], [beg, end]]

* funasr1.0 websocket-python

* funasr1.0 websocket-python

---------

Co-authored-by: shixian.shi <[email protected]>
Co-authored-by: 雾聪 <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 65396ee commit 4f224c8
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from funasr import AutoModel

model = AutoModel(model="damo/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727", model_revision="v2.0.4")
model = AutoModel(model="iic/punc_ct-transformer_zh-cn-common-vad_realtime-vocab272727", model_revision="v2.0.4")

inputs = "跨境河流是养育沿岸|人民的生命之源长期以来为帮助下游地区防灾减灾中方技术人员|在上游地区极为恶劣的自然条件下克服巨大困难甚至冒着生命危险|向印方提供汛期水文资料处理紧急事件中方重视印方在跨境河流问题上的关切|愿意进一步完善双方联合工作机制|凡是|中方能做的我们|都会去做而且会做得更好我请印度朋友们放心中国在上游的|任何开发利用都会经过科学|规划和论证兼顾上下游的利益"
vads = inputs.split("|")
Expand Down
3 changes: 2 additions & 1 deletion funasr/auto/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def prepare_data_iterator(data_in, input_len=None, data_type=None, key=None):
class AutoModel:

def __init__(self, **kwargs):
tables.print()
if kwargs.get("disable_log", False):
tables.print()

model, kwargs = self.build_model(**kwargs)

Expand Down
89 changes: 60 additions & 29 deletions runtime/python/websocket/funasr_wss_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
type=str,
default="5, 10, 5",
help="chunk")
parser.add_argument("--encoder_chunk_look_back",
type=int,
default=4,
help="chunk")
parser.add_argument("--decoder_chunk_look_back",
type=int,
default=0,
help="chunk")
parser.add_argument("--chunk_interval",
type=int,
default=10,
Expand Down Expand Up @@ -113,25 +121,36 @@ async def record_microphone():
fst_dict = {}
hotword_msg = ""
if args.hotword.strip() != "":
f_scp = open(args.hotword)
hot_lines = f_scp.readlines()
for line in hot_lines:
words = line.strip().split(" ")
if len(words) < 2:
print("Please checkout format of hotwords")
continue
try:
fst_dict[" ".join(words[:-1])] = int(words[-1])
except ValueError:
print("Please checkout format of hotwords")
hotword_msg=json.dumps(fst_dict)
if os.path.exists(args.hotword):
f_scp = open(args.hotword)
hot_lines = f_scp.readlines()
for line in hot_lines:
words = line.strip().split(" ")
if len(words) < 2:
print("Please checkout format of hotwords")
continue
try:
fst_dict[" ".join(words[:-1])] = int(words[-1])
except ValueError:
print("Please checkout format of hotwords")
hotword_msg = json.dumps(fst_dict)
else:
hotword_msg = args.hotword

use_itn=True
use_itn = True
if args.use_itn == 0:
use_itn=False

message = json.dumps({"mode": args.mode, "chunk_size": args.chunk_size, "chunk_interval": args.chunk_interval,
"wav_name": "microphone", "is_speaking": True, "hotwords":hotword_msg, "itn": use_itn})
message = json.dumps({"mode": args.mode,
"chunk_size": args.chunk_size,
"chunk_interval": args.chunk_interval,
"encoder_chunk_look_back": args.encoder_chunk_look_back,
"decoder_chunk_look_back": args.decoder_chunk_look_back,
"wav_name": "microphone",
"is_speaking": True,
"hotwords": hotword_msg,
"itn": use_itn,
})
#voices.put(message)
await websocket.send(message)
while True:
Expand All @@ -154,18 +173,21 @@ async def record_from_scp(chunk_begin, chunk_size):
fst_dict = {}
hotword_msg = ""
if args.hotword.strip() != "":
f_scp = open(args.hotword)
hot_lines = f_scp.readlines()
for line in hot_lines:
words = line.strip().split(" ")
if len(words) < 2:
print("Please checkout format of hotwords")
continue
try:
fst_dict[" ".join(words[:-1])] = int(words[-1])
except ValueError:
print("Please checkout format of hotwords")
hotword_msg=json.dumps(fst_dict)
if os.path.exists(args.hotword):
f_scp = open(args.hotword)
hot_lines = f_scp.readlines()
for line in hot_lines:
words = line.strip().split(" ")
if len(words) < 2:
print("Please checkout format of hotwords")
continue
try:
fst_dict[" ".join(words[:-1])] = int(words[-1])
except ValueError:
print("Please checkout format of hotwords")
hotword_msg = json.dumps(fst_dict)
else:
hotword_msg = args.hotword
print (hotword_msg)

sample_rate = args.audio_fs
Expand Down Expand Up @@ -203,8 +225,17 @@ async def record_from_scp(chunk_begin, chunk_size):
# print(stride)

# send first time
message = json.dumps({"mode": args.mode, "chunk_size": args.chunk_size, "chunk_interval": args.chunk_interval, "audio_fs":sample_rate,
"wav_name": wav_name, "wav_format": wav_format, "is_speaking": True, "hotwords":hotword_msg, "itn": use_itn})
message = json.dumps({"mode": args.mode,
"chunk_size": args.chunk_size,
"chunk_interval": args.chunk_interval,
"encoder_chunk_look_back": args.encoder_chunk_look_back,
"decoder_chunk_look_back": args.decoder_chunk_look_back,
"audio_fs":sample_rate,
"wav_name": wav_name,
"wav_format": wav_format,
"is_speaking": True,
"hotwords": hotword_msg,
"itn": use_itn})

#voices.put(message)
await websocket.send(message)
Expand Down
Loading

0 comments on commit 4f224c8

Please sign in to comment.