Add exception handling for cases when no Piper model exists.
Browse files- src/synthesize.py +16 -13
src/synthesize.py
CHANGED
@@ -9,7 +9,7 @@ from scipy.io import wavfile
|
|
9 |
from transformers import pipeline
|
10 |
import os
|
11 |
import numpy as np
|
12 |
-
from gradio_client import Client,
|
13 |
|
14 |
|
15 |
def synth_mms(text:str, model:str):
|
@@ -130,7 +130,7 @@ def synth_toucan(text:str, model:str):
|
|
130 |
result = client.predict(
|
131 |
prompt=text,
|
132 |
language=model,
|
133 |
-
reference_audio=
|
134 |
voice_seed=123,
|
135 |
prosody_creativity=0.1,
|
136 |
duration_scaling_factor=1,
|
@@ -153,14 +153,17 @@ def synth_piper(text:str, model:str):
|
|
153 |
|
154 |
NOTES: (1) This uses a Huggingface Gradio Space to compute via the API.
|
155 |
'''
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
9 |
from transformers import pipeline
|
10 |
import os
|
11 |
import numpy as np
|
12 |
+
from gradio_client import Client, handle_file
|
13 |
|
14 |
|
15 |
def synth_mms(text:str, model:str):
|
|
|
130 |
result = client.predict(
|
131 |
prompt=text,
|
132 |
language=model,
|
133 |
+
reference_audio=handle_file('https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'),
|
134 |
voice_seed=123,
|
135 |
prosody_creativity=0.1,
|
136 |
duration_scaling_factor=1,
|
|
|
153 |
|
154 |
NOTES: (1) This uses a Huggingface Gradio Space to compute via the API.
|
155 |
'''
|
156 |
+
if model is not None:
|
157 |
+
client = Client("k2-fsa/text-to-speech")
|
158 |
+
result = client.predict(
|
159 |
+
language=model[0],
|
160 |
+
repo_id=model[1],
|
161 |
+
text=text,
|
162 |
+
sid="0",
|
163 |
+
speed=1,
|
164 |
+
api_name="/process"
|
165 |
+
)
|
166 |
+
sampling_rate, wav = wavfile.read(result[0])
|
167 |
+
return wav, sampling_rate
|
168 |
+
else:
|
169 |
+
return None
|