@@ -35,10 +35,11 @@ def initialize_model(model_type, hotword):
3535 loaded_model ["model_type" ] = "normal"
3636 model = pipeline (
3737 task = Tasks .auto_speech_recognition ,
38- vad_model = "damo/speech_fsmn_vad_zh-cn-16k-common-pytorch" ,
3938 model = "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch" ,
39+ vad_model = "damo/speech_fsmn_vad_zh-cn-16k-common-pytorch" ,
4040 # lm_model='damo/speech_transformer_lm_zh-cn-common-vocab8404-pytorch',
41- punc_model = "damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch"
41+ punc_model = "damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch" ,
42+ timestamp_model = "damo/speech_timestamp_prediction-v1-16k-offline"
4243 )
4344 elif model_type == "long" :
4445 log .debug ("lodding model: long" )
@@ -72,6 +73,10 @@ def load_model(model_type, hotword):
7273 if loaded_model ["model_type" ] is None or loaded_model ["model_type" ] != model_type or (loaded_model ["model_type" ] == "hotword" and hotword_parm ["hotword" ] != hotword ):
7374 loaded_model ["model" ] = initialize_model (model_type , hotword )
7475
76+ @app .on_event ("startup" )
77+ async def startup_event ():
78+ load_model (model_type = "long" , hotword = None )
79+ rec_result = loaded_model ["model" ](audio_in = "./16000_001.wav" )
7580
7681@app .post ("/asr" , tags = ["ASR" ], summary = "聚合ASR模型接口服务" )
7782async def predict (items : Audio ):
@@ -93,14 +98,20 @@ async def predict(items: Audio):
9398 log .info (f"Received a url in string, url: { items .file } " )
9499 decoded_data = requests .get (items .file ).content
95100
96- load_model (model_type = items . model_type , hotword = items .hotword )
101+ load_model (model_type = "long" , hotword = items .hotword )
97102 rec_result = loaded_model ["model" ](audio_in = decoded_data )
98- if items .model_type == 'normal' or items .model_type == 'long' :
99- rec_result = {
100- "text" : rec_result ["text" ]
101- }
103+ result = []
102104 log .info (rec_result )
103- return rec_result
105+ for sentence in rec_result ["sentences" ]:
106+ result .append (
107+ {
108+ "text" : sentence ["text" ],
109+ "start" : sentence ["start" ] / 1000.0 ,
110+ "end" : sentence ["end" ] / 1000.0
111+ }
112+ )
113+ log .info (result )
114+ return result
104115
105116@app .get ("/health" )
106117async def health_check ():
0 commit comments