Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,35 @@
|
|
| 1 |
-
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
from TTS.api import TTS
|
| 5 |
import os
|
|
|
|
|
|
|
| 6 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
|
|
|
| 9 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 10 |
|
| 11 |
-
|
| 12 |
def clone(text, audio):
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
outputs=gr.Audio(type='filepath'),
|
| 19 |
-
title='Voice Clone Trial',
|
| 20 |
-
theme = gr.themes.Base(primary_hue="red",secondary_hue="orange",neutral_hue="black"),
|
| 21 |
-
)
|
| 22 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from TTS.api import TTS
|
| 4 |
import os
|
| 5 |
+
|
| 6 |
+
# Agree to the Coqui license terms
|
| 7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 8 |
|
| 9 |
+
# Initialize device for GPU or CPU
|
| 10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
|
| 12 |
+
# Initialize TTS model
|
| 13 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 14 |
|
| 15 |
+
# Define clone function for Gradio interface
|
| 16 |
def clone(text, audio):
|
| 17 |
+
# Use the reference audio and synthesize speech
|
| 18 |
+
output_path = "./output.wav"
|
| 19 |
+
tts.tts_to_file(text=text, speaker_wav=audio, language="en", file_path=output_path)
|
| 20 |
+
return output_path
|
| 21 |
+
|
| 22 |
+
# Set up the Gradio Interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=clone,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Textbox(label='Text'),
|
| 27 |
+
gr.Audio(type='filepath', label='Voice reference audio file')
|
| 28 |
+
],
|
| 29 |
+
outputs=gr.Audio(type='filepath'),
|
| 30 |
+
title='Voice Clone Trial',
|
| 31 |
+
theme=gr.themes.Base(primary_hue="red", secondary_hue="orange", neutral_hue="black"),
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
# Launch the interface
|
| 35 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|