Spaces:
Build error
Build error
LPhilp1943
commited on
Commit
•
592ca27
1
Parent(s):
792c625
Update app.py
Browse files
app.py
CHANGED
@@ -32,9 +32,13 @@ def speech_to_text(input_audio_or_text):
|
|
32 |
return transcription.strip()
|
33 |
|
34 |
def text_to_speech(text):
|
|
|
|
|
|
|
|
|
35 |
text = text.lower().translate(str.maketrans('', '', string.punctuation))
|
36 |
inputs = tts_tokenizer(text, return_tensors="pt")
|
37 |
-
inputs['input_ids'] = inputs['input_ids'].long() #
|
38 |
with torch.no_grad():
|
39 |
output = tts_model(**inputs).waveform
|
40 |
waveform = output.numpy().squeeze()
|
@@ -59,4 +63,4 @@ iface = gr.Interface(
|
|
59 |
description="This app converts speech to text and then back to speech, ensuring the output audio is resampled to 16kHz."
|
60 |
)
|
61 |
|
62 |
-
iface.launch(share=True)
|
|
|
32 |
return transcription.strip()
|
33 |
|
34 |
def text_to_speech(text):
|
35 |
+
# Ensure the text input is not empty to avoid padding errors in the transformer model
|
36 |
+
if not text.strip():
|
37 |
+
return "The text input is empty, please provide a valid string."
|
38 |
+
|
39 |
text = text.lower().translate(str.maketrans('', '', string.punctuation))
|
40 |
inputs = tts_tokenizer(text, return_tensors="pt")
|
41 |
+
inputs['input_ids'] = inputs['input_ids'].long() # Ensure input_ids are of type Long
|
42 |
with torch.no_grad():
|
43 |
output = tts_model(**inputs).waveform
|
44 |
waveform = output.numpy().squeeze()
|
|
|
63 |
description="This app converts speech to text and then back to speech, ensuring the output audio is resampled to 16kHz."
|
64 |
)
|
65 |
|
66 |
+
iface.launch(share=True)
|