Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ def tts_get_voices_list():
|
|
25 |
|
26 |
return voices
|
27 |
|
28 |
-
def
|
29 |
tts = asyncio.run(edge_tts.Communicate(txt, voice).save('audio.mp3'))
|
30 |
audio, sr = librosa.load('audio.mp3', sr=16000, mono=True)
|
31 |
raw_path = io.BytesIO()
|
@@ -33,23 +33,21 @@ def tts_mode(txt, voice):
|
|
33 |
raw_path.seek(0)
|
34 |
model = Svc(fr"Herta-Svc/G_10000.pth", f"Herta-Svc/config.json", device = 'cpu')
|
35 |
out_audio, out_sr = model.infer('speaker0', 0, raw_path, auto_predict_f0 = True,)
|
36 |
-
|
37 |
-
return (44100, out_audio.cpu().numpy())
|
38 |
-
|
39 |
-
def audio_infer_mode(input_audio):
|
40 |
-
sampling_rate, audio = input_audio
|
41 |
-
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
42 |
|
43 |
-
if
|
44 |
-
audio =
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
return (44100, out_audio.cpu().numpy())
|
55 |
|
@@ -84,6 +82,5 @@ if __name__ == '__main__':
|
|
84 |
tts_voice = gr.Dropdown.update(choices= tts_get_voices_list(), visible = True, show_label = True)
|
85 |
audio_input = gr.Audio.update(label = 'Input Audio', visible = False, show_label = False)
|
86 |
|
87 |
-
btn_submit.click(
|
88 |
-
|
89 |
app.queue(concurrency_count=1, api_open=args.api).launch(share=args.share)
|
|
|
25 |
|
26 |
return voices
|
27 |
|
28 |
+
def infer(txt, input_audio, voice, audio_mode):
|
29 |
tts = asyncio.run(edge_tts.Communicate(txt, voice).save('audio.mp3'))
|
30 |
audio, sr = librosa.load('audio.mp3', sr=16000, mono=True)
|
31 |
raw_path = io.BytesIO()
|
|
|
33 |
raw_path.seek(0)
|
34 |
model = Svc(fr"Herta-Svc/G_10000.pth", f"Herta-Svc/config.json", device = 'cpu')
|
35 |
out_audio, out_sr = model.infer('speaker0', 0, raw_path, auto_predict_f0 = True,)
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
if audio_mode:
|
38 |
+
sampling_rate, audio = input_audio
|
39 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
40 |
+
|
41 |
+
if len(audio.shape) > 1:
|
42 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
43 |
+
if sampling_rate != 16000:
|
44 |
+
audio = librosa.resample(audio, org_sr=sampling_rate, target_sr=16000)
|
45 |
|
46 |
+
raw_path = io.BytesIO()
|
47 |
+
soundfile.write(raw_path, audio, 16000, format="wav")
|
48 |
+
raw_path.seek(0)
|
49 |
+
model = Svc(fr"Herta-Svc/G_10000.pth", f"Herta-Svc/config.json", device = 'cpu')
|
50 |
+
out_audio, out_sr = model.infer('speaker0', 0, raw_path, auto_predict_f0 = True,)
|
51 |
|
52 |
return (44100, out_audio.cpu().numpy())
|
53 |
|
|
|
82 |
tts_voice = gr.Dropdown.update(choices= tts_get_voices_list(), visible = True, show_label = True)
|
83 |
audio_input = gr.Audio.update(label = 'Input Audio', visible = False, show_label = False)
|
84 |
|
85 |
+
btn_submit.click(infer, [tts_text, audio_input, tts_voice], [audio_output])
|
|
|
86 |
app.queue(concurrency_count=1, api_open=args.api).launch(share=args.share)
|