@@ -72,28 +72,6 @@ def load_model(model_type, hotword):
7272 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 ):
7373 loaded_model ["model" ] = initialize_model (model_type , hotword )
7474
75- def convert_audio_to_wav (binary_data ):
76- byte_stream = io .BytesIO (binary_data )
77- formats = ['mp3' , 'wav' , 'ogg' , 'flv' , 'mp4' , 'aac' ]
78- audio = None
79- for format in formats :
80- byte_stream .seek (0 ) # reset byte stream position
81- try :
82- audio = AudioSegment .from_file (byte_stream , format = format )
83- break
84- except :
85- pass
86- if audio is None :
87- raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST )
88- if audio .channels > 1 :
89- audio = audio .set_channels (1 )
90- audio = audio .set_frame_rate (16000 )
91- buffer = io .BytesIO ()
92- audio .export (buffer , format = 'wav' )
93- binary_data_resampled = buffer .getvalue ()
94-
95- return binary_data_resampled
96-
9775
9876@app .post ("/asr" , tags = ["ASR" ], summary = "聚合ASR模型接口服务" )
9977async def predict (items : Audio ):
@@ -115,7 +93,6 @@ async def predict(items: Audio):
11593 log .info (f"Received a url in string, url: { items .file } " )
11694 decoded_data = requests .get (items .file ).content
11795
118- decoded_data = convert_audio_to_wav (decoded_data )
11996 load_model (model_type = items .model_type , hotword = items .hotword )
12097 rec_result = loaded_model ["model" ](audio_in = decoded_data )
12198 if items .model_type == 'normal' or items .model_type == 'long' :
0 commit comments