Skip to content

Commit

Permalink
Merge pull request #214 from jiangyuxiaoxiao/master
Browse files Browse the repository at this point in the history
fix server_fastapi.py: 修复bug。
  • Loading branch information
jiangyuxiaoxiao authored Dec 4, 2023
2 parents 67de3ba + 2b178ba commit 15603dc
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions server_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,34 @@ async def _voice(
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,
Expand All @@ -231,31 +254,10 @@ async def _voice(
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
Expand Down

0 comments on commit 15603dc

Please sign in to comment.