From 2b178ba1835656090c27be566b83ff0e0cd8bfce Mon Sep 17 00:00:00 2001 From: Sora <654163754@qq.com> Date: Mon, 4 Dec 2023 12:09:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=20server=5Ffastapi.py:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server_fastapi.py | 62 ++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/server_fastapi.py b/server_fastapi.py index e858f90..485b961 100644 --- a/server_fastapi.py +++ b/server_fastapi.py @@ -214,11 +214,34 @@ if __name__ == "__main__": if auto_translate: text = trans.translate(Sentence=text, to_Language=language.lower()) if reference_audio is not None: - with BytesIO(await reference_audio.read()) as ref_audio: - if not auto_split: - with torch.no_grad(): - audio = infer( - text=text, + ref_audio = BytesIO(await reference_audio.read()) + else: + ref_audio = reference_audio + if not auto_split: + with torch.no_grad(): + audio = infer( + text=text, + sdp_ratio=sdp_ratio, + noise_scale=noise, + noise_scale_w=noisew, + length_scale=length, + sid=speaker_name, + language=language, + hps=loaded_models.models[model_id].hps, + net_g=loaded_models.models[model_id].net_g, + device=loaded_models.models[model_id].device, + emotion=emotion, + reference_audio=ref_audio, + ) + audio = gradio.processing_utils.convert_to_16_bit_wav(audio) + else: + texts = cut_sent(text) + audios = [] + with torch.no_grad(): + for t in texts: + audios.append( + infer( + text=t, sdp_ratio=sdp_ratio, noise_scale=noise, noise_scale_w=noisew, @@ -231,31 +254,10 @@ if __name__ == "__main__": emotion=emotion, reference_audio=ref_audio, ) - audio = gradio.processing_utils.convert_to_16_bit_wav(audio) - else: - texts = cut_sent(text) - audios = [] - with torch.no_grad(): - for t in texts: - audios.append( - infer( - text=t, - sdp_ratio=sdp_ratio, - noise_scale=noise, - noise_scale_w=noisew, - length_scale=length, - sid=speaker_name, - language=language, - hps=loaded_models.models[model_id].hps, - net_g=loaded_models.models[model_id].net_g, - device=loaded_models.models[model_id].device, - emotion=emotion, - reference_audio=ref_audio, - ) - ) - audios.append(np.zeros(int(44100 * 0.2))) - audio = np.concatenate(audios) - audio = gradio.processing_utils.convert_to_16_bit_wav(audio) + ) + audios.append(np.zeros(int(44100 * 0.2))) + audio = np.concatenate(audios) + audio = gradio.processing_utils.convert_to_16_bit_wav(audio) with BytesIO() as wavContent: wavfile.write( wavContent, loaded_models.models[model_id].hps.data.sampling_rate, audio