mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
update paraformer online python websocket code
This commit is contained in:
parent
111d50159d
commit
97eb2bd656
@ -51,7 +51,8 @@ class Funasr_websocket_recognizer():
|
|||||||
stride = int(60 * chunk_size[1]/ chunk_interval / 1000 * 16000 * 2)
|
stride = int(60 * chunk_size[1]/ chunk_interval / 1000 * 16000 * 2)
|
||||||
chunk_num = (len(audio_bytes) - 1) // stride + 1
|
chunk_num = (len(audio_bytes) - 1) // stride + 1
|
||||||
|
|
||||||
message = json.dumps({"mode": mode, "chunk_size": chunk_size, "chunk_interval": chunk_interval,
|
message = json.dumps({"mode": args.mode, "chunk_size": args.chunk_size, "encoder_chunk_look_back": 4,
|
||||||
|
"decoder_chunk_look_back": 1, "chunk_interval": args.chunk_interval,
|
||||||
"wav_name": wav_name, "is_speaking": True})
|
"wav_name": wav_name, "is_speaking": True})
|
||||||
|
|
||||||
self.websocket.send(message)
|
self.websocket.send(message)
|
||||||
@ -131,4 +132,4 @@ if __name__ == '__main__':
|
|||||||
print("text",text)
|
print("text",text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,14 @@ parser.add_argument("--chunk_size",
|
|||||||
type=str,
|
type=str,
|
||||||
default="5, 10, 5",
|
default="5, 10, 5",
|
||||||
help="chunk")
|
help="chunk")
|
||||||
|
parser.add_argument("--encoder_chunk_look_back",
|
||||||
|
type=int,
|
||||||
|
default=4,
|
||||||
|
help="number of chunks to lookback for encoder self-attention")
|
||||||
|
parser.add_argument("--decoder_chunk_look_back",
|
||||||
|
type=int,
|
||||||
|
default=1,
|
||||||
|
help="number of encoder chunks to lookback for decoder cross-attention")
|
||||||
parser.add_argument("--chunk_interval",
|
parser.add_argument("--chunk_interval",
|
||||||
type=int,
|
type=int,
|
||||||
default=10,
|
default=10,
|
||||||
@ -99,7 +107,8 @@ async def record_microphone():
|
|||||||
input=True,
|
input=True,
|
||||||
frames_per_buffer=CHUNK)
|
frames_per_buffer=CHUNK)
|
||||||
|
|
||||||
message = json.dumps({"mode": args.mode, "chunk_size": args.chunk_size, "chunk_interval": args.chunk_interval,
|
message = json.dumps({"mode": args.mode, "chunk_size": args.chunk_size, "encoder_chunk_look_back": args.encoder_chunk_look_back,
|
||||||
|
"decoder_chunk_look_back": args.decoder_chunk_look_back, "chunk_interval": args.chunk_interval,
|
||||||
"wav_name": "microphone", "is_speaking": True})
|
"wav_name": "microphone", "is_speaking": True})
|
||||||
#voices.put(message)
|
#voices.put(message)
|
||||||
await websocket.send(message)
|
await websocket.send(message)
|
||||||
|
|||||||
@ -103,8 +103,8 @@ inference_pipeline_asr_online = pipeline(
|
|||||||
model=args.asr_model_online,
|
model=args.asr_model_online,
|
||||||
ngpu=args.ngpu,
|
ngpu=args.ngpu,
|
||||||
ncpu=args.ncpu,
|
ncpu=args.ncpu,
|
||||||
model_revision='v1.0.4',
|
model_revision='v1.0.7',
|
||||||
update_model='v1.0.4',
|
update_model='v1.0.7',
|
||||||
mode='paraformer_streaming')
|
mode='paraformer_streaming')
|
||||||
|
|
||||||
print("model loaded! only support one client at the same time now!!!!")
|
print("model loaded! only support one client at the same time now!!!!")
|
||||||
@ -159,6 +159,10 @@ async def ws_serve(websocket, path):
|
|||||||
websocket.wav_name = messagejson.get("wav_name")
|
websocket.wav_name = messagejson.get("wav_name")
|
||||||
if "chunk_size" in messagejson:
|
if "chunk_size" in messagejson:
|
||||||
websocket.param_dict_asr_online["chunk_size"] = messagejson["chunk_size"]
|
websocket.param_dict_asr_online["chunk_size"] = messagejson["chunk_size"]
|
||||||
|
if "encoder_chunk_look_back" in messagejson:
|
||||||
|
websocket.param_dict_asr_online["encoder_chunk_look_back"] = messagejson["encoder_chunk_look_back"]
|
||||||
|
if "decoder_chunk_look_back" in messagejson:
|
||||||
|
websocket.param_dict_asr_online["decoder_chunk_look_back"] = messagejson["decoder_chunk_look_back"]
|
||||||
if "mode" in messagejson:
|
if "mode" in messagejson:
|
||||||
websocket.mode = messagejson["mode"]
|
websocket.mode = messagejson["mode"]
|
||||||
if len(frames_asr_online) > 0 or len(frames_asr) > 0 or not isinstance(message, str):
|
if len(frames_asr_online) > 0 or len(frames_asr) > 0 or not isinstance(message, str):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user