Update app.py
Browse filesimport os
import gradio as gr
from TTS.api import TTS
import torch
os.environ["COQUI_TOS_AGREED"] = "1"
device = "cuda" if torch.cuda.is_available() else "cpu"
print("Loading XTTS...")
try:
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
except:
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
def clone(text, lang, ref):
out = "out.wav"
tts.tts_to_file(text=text, file_path=out, speaker_wav=ref, language=lang)
return out
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"]
with gr.Blocks() as demo:
t=gr.Textbox(label="Text")
l=gr.Dropdown(label="Lang", choices=LANGS, value="fr")
r=gr.Audio(label="Ref", type="filepath")
o=gr.Audio(label="Out")
gr.Button("Generate").click(clone, [t,l,r], [o])
demo.launch()
|
@@ -8,23 +8,22 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 8 |
|
| 9 |
print("Loading XTTS...")
|
| 10 |
try:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
print(f"Error loading by name: {e}")
|
| 15 |
-
# Fallback to general initialization which triggers download
|
| 16 |
-
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 17 |
|
| 18 |
def clone(text, lang, ref):
|
| 19 |
-
|
| 20 |
tts.tts_to_file(text=text, file_path=out, speaker_wav=ref, language=lang)
|
| 21 |
return out
|
| 22 |
|
| 23 |
-
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
print("Loading XTTS...")
|
| 10 |
try:
|
| 11 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
| 12 |
+
except:
|
| 13 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def clone(text, lang, ref):
|
| 16 |
+
out = "out.wav"
|
| 17 |
tts.tts_to_file(text=text, file_path=out, speaker_wav=ref, language=lang)
|
| 18 |
return out
|
| 19 |
|
| 20 |
+
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"]
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
t=gr.Textbox(label="Text")
|
| 24 |
+
l=gr.Dropdown(label="Lang", choices=LANGS, value="fr")
|
| 25 |
+
r=gr.Audio(label="Ref", type="filepath")
|
| 26 |
+
o=gr.Audio(label="Out")
|
| 27 |
+
gr.Button("Generate").click(clone, [t,l,r], [o])
|
| 28 |
+
|
| 29 |
+
demo.launch()
|