Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,37 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from TTS.
|
|
|
|
|
|
|
| 4 |
|
| 5 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 6 |
|
| 7 |
-
print("
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def clone_voice(text, language, reference_audio):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
text=text,
|
| 14 |
-
file_path=output_path,
|
| 15 |
-
speaker_wav=reference_audio,
|
| 16 |
-
language=language
|
| 17 |
-
)
|
| 18 |
-
return output_path
|
| 19 |
|
| 20 |
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"]
|
| 21 |
|
| 22 |
demo = gr.Interface(
|
| 23 |
fn=clone_voice,
|
| 24 |
inputs=[
|
| 25 |
-
gr.Textbox(label="Text
|
| 26 |
gr.Dropdown(choices=LANGS, value="fr", label="Language"),
|
| 27 |
-
gr.Audio(label="Reference
|
| 28 |
],
|
| 29 |
-
outputs=gr.Audio(label="
|
| 30 |
title="XTTS v2 Voice Cloning"
|
| 31 |
)
|
| 32 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from TTS.tts.configs.xtts_config import XttsConfig
|
| 4 |
+
from TTS.tts.models.xtts import Xtts
|
| 5 |
+
from huggingface_hub import snapshot_download
|
| 6 |
|
| 7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 8 |
|
| 9 |
+
print("Downloading XTTS-v2 model...")
|
| 10 |
+
repo_id = "XTTS-v2"
|
| 11 |
+
if not os.path.exists(repo_id):
|
| 12 |
+
snapshot_download(repo_id="coqui/XTTS-v2", local_dir=repo_id, allow_patterns=["*.json", "*.pth", "*.wav"])
|
| 13 |
+
|
| 14 |
+
print("Loading model...")
|
| 15 |
+
config = XttsConfig()
|
| 16 |
+
config.load_json("XTTS-v2/config.json")
|
| 17 |
+
model = Xtts.init_from_config(config)
|
| 18 |
+
model.load_checkpoint(config, checkpoint_dir="XTTS-v2", eval=True)
|
| 19 |
+
print("Model loaded!")
|
| 20 |
|
| 21 |
def clone_voice(text, language, reference_audio):
|
| 22 |
+
outputs = model.synthesize(text, config, speaker_wav=reference_audio, language=language)
|
| 23 |
+
return (24000, outputs["wav"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"]
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=clone_voice,
|
| 29 |
inputs=[
|
| 30 |
+
gr.Textbox(label="Text"),
|
| 31 |
gr.Dropdown(choices=LANGS, value="fr", label="Language"),
|
| 32 |
+
gr.Audio(label="Reference Audio", type="filepath")
|
| 33 |
],
|
| 34 |
+
outputs=gr.Audio(label="Output"),
|
| 35 |
title="XTTS v2 Voice Cloning"
|
| 36 |
)
|
| 37 |
|