khof312 commited on
Commit
facd38d
·
1 Parent(s): 332bb9f

Add exception handling for cases when no Piper model exists.

Browse files
Files changed (1) hide show
  1. 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, file
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=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,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
- client = Client("k2-fsa/text-to-speech")
157
- result = client.predict(
158
- language=model[0],
159
- repo_id=model[1],
160
- text=text,
161
- sid="0",
162
- speed=1,
163
- api_name="/process"
164
- )
165
- sampling_rate, wav = wavfile.read(result[0])
166
- return wav, sampling_rate
 
 
 
 
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