Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5Hif
|
|
9 |
from speechbrain.pretrained import EncoderClassifier
|
10 |
from datasets import load_dataset
|
11 |
from huggingface_hub import hf_hub_download
|
|
|
12 |
|
13 |
|
14 |
from piper import PiperVoice
|
@@ -25,7 +26,9 @@ config_path = hf_hub_download(repo_id="fahadqazi/piper-sindhi", filename="model.
|
|
25 |
|
26 |
voice = PiperVoice.load(model_path=model_path, config_path=config_path, use_cuda=device=="cuda")
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
|
31 |
def load_models_and_data():
|
@@ -139,8 +142,10 @@ def text_to_speech(text, audio_file=None):
|
|
139 |
|
140 |
# return (16000, speech_np)
|
141 |
|
142 |
-
# Generate speech
|
143 |
-
|
|
|
|
|
144 |
|
145 |
# Save the audio to a file
|
146 |
# with open("output.wav", "wb") as f:
|
@@ -148,7 +153,7 @@ def text_to_speech(text, audio_file=None):
|
|
148 |
|
149 |
# return audio_file
|
150 |
|
151 |
-
return
|
152 |
|
153 |
|
154 |
iface = gr.Interface(
|
|
|
9 |
from speechbrain.pretrained import EncoderClassifier
|
10 |
from datasets import load_dataset
|
11 |
from huggingface_hub import hf_hub_download
|
12 |
+
import uuid
|
13 |
|
14 |
|
15 |
from piper import PiperVoice
|
|
|
26 |
|
27 |
voice = PiperVoice.load(model_path=model_path, config_path=config_path, use_cuda=device=="cuda")
|
28 |
|
29 |
+
synthesize_args = {
|
30 |
+
"speaker_id": 0,
|
31 |
+
}
|
32 |
|
33 |
|
34 |
def load_models_and_data():
|
|
|
142 |
|
143 |
# return (16000, speech_np)
|
144 |
|
145 |
+
# Generate speech: Write to file
|
146 |
+
output_file = f"{uuid.uuid4()}.wav"
|
147 |
+
with wave.open(output_file, "wb") as wav_file:
|
148 |
+
voice.synthesize(normalized_text, wav_file, **synthesize_args)
|
149 |
|
150 |
# Save the audio to a file
|
151 |
# with open("output.wav", "wb") as f:
|
|
|
153 |
|
154 |
# return audio_file
|
155 |
|
156 |
+
return output_file
|
157 |
|
158 |
|
159 |
iface = gr.Interface(
|