Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,59 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mport gradio as gr
|
2 |
+
import torch
|
3 |
+
from datasets import load_dataset
|
4 |
+
from transformers import pipeline, SpeechT5Processor, SpeechT5HifiGan, SpeechT5ForTextToSpeech
|
5 |
|
6 |
+
model_id = "ovieyra21/es_speecht5_tts_mabama" # 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(model_id)
|
15 |
+
|
16 |
+
replacements = [
|
17 |
+
("Ã ", "a"),
|
18 |
+
("â", "a"),
|
19 |
+
("ç", "c"),
|
20 |
+
("è", "e"),
|
21 |
+
("ë", "e"),
|
22 |
+
("î", "i"),
|
23 |
+
("ï", "i"),
|
24 |
+
("ô", "o"),
|
25 |
+
("ù", "u"),
|
26 |
+
("û", "u"),
|
27 |
+
("ü", "u"),
|
28 |
+
]
|
29 |
+
|
30 |
+
|
31 |
+
title = "Text-to-Speech"
|
32 |
+
description = """
|
33 |
+
Demo for text-to-speech translation in French. Demo uses [Sandiago21/speecht5_finetuned_facebook_voxpopuli_french](https://huggingface.co/Sandiago21/speecht5_finetuned_facebook_voxpopuli_french) checkpoint, which is based on Microsoft's
|
34 |
+
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model and is fine-tuned in French Audio dataset
|
35 |
+
![Text-to-Speech (TTS)"](https://geekflare.com/wp-content/uploads/2021/07/texttospeech-1200x385.png "Diagram of Text-to-Speech (TTS)")
|
36 |
+
"""
|
37 |
+
|
38 |
+
|
39 |
+
def cleanup_text(text):
|
40 |
+
for src, dst in replacements:
|
41 |
+
text = text.replace(src, dst)
|
42 |
+
return text
|
43 |
+
|
44 |
+
def synthesize_speech(text):
|
45 |
+
text = cleanup_text(text)
|
46 |
+
inputs = processor(text=text, return_tensors="pt")
|
47 |
+
|
48 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
49 |
+
|
50 |
+
return gr.Audio.update(value=(16000, speech.cpu().numpy()))
|
51 |
+
|
52 |
+
syntesize_speech_gradio = gr.Interface(
|
53 |
+
synthesize_speech,
|
54 |
+
inputs = gr.Textbox(label="Text", placeholder="Type something here..."),
|
55 |
+
outputs=gr.Audio(),
|
56 |
+
examples=["Probando audio"],
|
57 |
+
title=title,
|
58 |
+
description=description,
|
59 |
+
).launch()
|