Spaces:
Runtime error
Runtime error
Commit
·
1845fa8
1
Parent(s):
84d766c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the text-to-speech pipeline from Hugging Face Spaces
|
5 |
+
nlp = pipeline("tts", model="facebook/tts", device=0)
|
6 |
+
|
7 |
+
# Define the Gradio interface
|
8 |
+
def text_to_speech(text, voice):
|
9 |
+
# Select the appropriate voice model based on the user's choice
|
10 |
+
if voice == 'English (US)':
|
11 |
+
voice_model = "facebook/tts-yinipar"
|
12 |
+
elif voice == 'English (UK)':
|
13 |
+
voice_model = "facebook/tts-russell"
|
14 |
+
elif voice == 'French':
|
15 |
+
voice_model = "facebook/wav2vec2-large-xlsr-53-french"
|
16 |
+
elif voice == 'German':
|
17 |
+
voice_model = "facebook/wav2vec2-large-xlsr-53-german"
|
18 |
+
else:
|
19 |
+
voice_model = "facebook/tts-hifigan"
|
20 |
+
|
21 |
+
# Generate speech from the input text using the selected voice model
|
22 |
+
speech = nlp(text, model=voice_model)[0]['audio']
|
23 |
+
|
24 |
+
return speech
|
25 |
+
|
26 |
+
# Create the Gradio interface
|
27 |
+
iface = gr.Interface(fn=text_to_speech, inputs=["text", "dropdown"],
|
28 |
+
outputs="audio", title="Text-to-Speech App",
|
29 |
+
description="Select a text and a voice to hear the speech")
|
30 |
+
|
31 |
+
# Add voice options to the dropdown input
|
32 |
+
iface.inputs[1].choices = ["English (US)", "English (UK)", "French", "German"]
|
33 |
+
|
34 |
+
# Launch the Gradio interface
|
35 |
+
iface.launch()
|