Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import Text2SpeechForConditionalGeneration, Text2SpeechTokenizer
|
3 |
+
|
4 |
+
# Load TTS model and tokenizer
|
5 |
+
model_name = "facebook/wav2vec2-base-960h"
|
6 |
+
tts_model = Text2SpeechForConditionalGeneration.from_pretrained(model_name)
|
7 |
+
tokenizer = Text2SpeechTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def text_to_speech(text):
|
10 |
+
inputs = tokenizer(text, return_tensors="pt", clean_up_tokenization_spaces=True)
|
11 |
+
with gr.Output() as out:
|
12 |
+
speech = tts_model.generate(**inputs)
|
13 |
+
gr.Audio(speech[0].numpy(), type="audio/wav")
|
14 |
+
|
15 |
+
iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio")
|
16 |
+
iface.launch()
|