Spaces:
Runtime error
Runtime error
Sandiago21
commited on
Commit
•
4e03c16
1
Parent(s):
79ef804
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- app.py +43 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji: 🐢
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.36.1
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: text-to-speech-spanish
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 3.36.0
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from datasets import load_dataset
|
4 |
+
from transformers import pipeline, SpeechT5Processor, SpeechT5HifiGan, SpeechT5ForTextToSpeech
|
5 |
+
|
6 |
+
model_id = "Sandiago21/speecht5_finetuned_voxpopuli_spanish" # update with your model id
|
7 |
+
# pipe = pipeline("automatic-speech-recognition", model=model_id)
|
8 |
+
model = SpeechT5ForTextToSpeech.from_pretrained(model_id)
|
9 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
10 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
11 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7440]["xvector"]).unsqueeze(0)
|
12 |
+
|
13 |
+
checkpoint = "microsoft/speecht5_tts"
|
14 |
+
processor = SpeechT5Processor.from_pretrained(checkpoint)
|
15 |
+
|
16 |
+
replacements = [
|
17 |
+
("á", "a"),
|
18 |
+
("í", "i"),
|
19 |
+
("ñ", "n"),
|
20 |
+
("ó", "o"),
|
21 |
+
("ú", "u"),
|
22 |
+
("ü", "u"),
|
23 |
+
]
|
24 |
+
|
25 |
+
def cleanup_text(text):
|
26 |
+
for src, dst in replacements:
|
27 |
+
text = text.replace(src, dst)
|
28 |
+
return text
|
29 |
+
|
30 |
+
def synthesize_speech(text):
|
31 |
+
text = cleanup_text(text)
|
32 |
+
inputs = processor(text=text, return_tensors="pt")
|
33 |
+
|
34 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
35 |
+
|
36 |
+
return gr.Audio.update(value=(16000, speech.cpu().numpy()))
|
37 |
+
|
38 |
+
syntesize_speech_gradio = gr.Interface(
|
39 |
+
synthesize_speech,
|
40 |
+
inputs = gr.Textbox(label="Text", placeholder="Type something here..."),
|
41 |
+
outputs=gr.Audio(),
|
42 |
+
).launch()
|
43 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
datasets
|
4 |
+
torchaudio
|
5 |
+
sentencepiece==0.1.99
|
6 |
+
|