Spaces:
Build error
Build error
Aseem Gupta
commited on
Commit
Β·
a416ccf
1
Parent(s):
c636952
test2
Browse files- app.py +29 -41
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,49 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
return f"Language {language} not supported yet.", None
|
| 18 |
-
|
| 19 |
-
# Convert text to the target language (if needed)
|
| 20 |
-
if detect(text_prompt) != supported_languages[language]:
|
| 21 |
-
# For now, we assume text is already in the desired language
|
| 22 |
-
pass
|
| 23 |
-
|
| 24 |
-
# Generate speech
|
| 25 |
-
try:
|
| 26 |
-
result = tts(text=text_prompt, speaker=audio)
|
| 27 |
-
return "Speech generated successfully!", result["audio"]
|
| 28 |
-
except Exception as e:
|
| 29 |
-
return f"Error: {str(e)}", None
|
| 30 |
|
| 31 |
# Gradio Interface
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
-
gr.Markdown("
|
| 34 |
|
| 35 |
with gr.Row():
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
# Launch the app
|
| 49 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from TTS.api import TTS
|
| 3 |
+
|
| 4 |
+
# Load the XTTS-v2 model
|
| 5 |
+
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=True)
|
| 6 |
+
|
| 7 |
+
# Define the function for voice cloning
|
| 8 |
+
def generate_voice(text, speaker_audio):
|
| 9 |
+
output_path = "output.wav"
|
| 10 |
+
tts.tts_to_file(
|
| 11 |
+
text=text,
|
| 12 |
+
speaker_wav=speaker_audio.name,
|
| 13 |
+
file_path=output_path,
|
| 14 |
+
language="en"
|
| 15 |
+
)
|
| 16 |
+
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Gradio Interface
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown("# π£οΈ Voice Cloning with Coqui XTTS-v2")
|
| 21 |
|
| 22 |
with gr.Row():
|
| 23 |
+
text_input = gr.Textbox(label="Enter Text", placeholder="Type the text you want to synthesize...")
|
| 24 |
+
speaker_audio_input = gr.Audio(label="Upload Speaker Audio (WAV)", type="file")
|
| 25 |
+
|
| 26 |
+
output_audio = gr.Audio(label="Generated Voice", type="filepath")
|
| 27 |
+
|
| 28 |
+
generate_button = gr.Button("Generate Voice")
|
| 29 |
+
|
| 30 |
+
generate_button.click(
|
| 31 |
+
fn=generate_voice,
|
| 32 |
+
inputs=[text_input, speaker_audio_input],
|
| 33 |
+
outputs=output_audio
|
| 34 |
+
)
|
| 35 |
|
| 36 |
+
# Launch the Gradio app
|
| 37 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -2,3 +2,4 @@ gradio
|
|
| 2 |
torch
|
| 3 |
transformers
|
| 4 |
langdetect
|
|
|
|
|
|
| 2 |
torch
|
| 3 |
transformers
|
| 4 |
langdetect
|
| 5 |
+
TTS
|