Update app.py
Browse files
app.py
CHANGED
|
@@ -11,15 +11,17 @@ 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 |
-
|
|
|
|
|
|
|
| 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"]
|
|
@@ -27,12 +29,13 @@ LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja
|
|
| 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="
|
| 35 |
-
title="XTTS v2 Voice Cloning"
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
-
demo.launch()
|
|
|
|
| 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 on CPU...")
|
| 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 successfully on CPU!")
|
| 20 |
|
| 21 |
def clone_voice(text, language, reference_audio):
|
| 22 |
+
if not text or not reference_audio:
|
| 23 |
+
return None
|
| 24 |
+
outputs = model.synthesize(text, config, speaker_wav=reference_audio, language=language, enable_text_splitting=True)
|
| 25 |
return (24000, outputs["wav"])
|
| 26 |
|
| 27 |
LANGS = ["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn","ja","ko","hu"]
|
|
|
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=clone_voice,
|
| 31 |
inputs=[
|
| 32 |
+
gr.Textbox(label="Text", placeholder="Enter text to synthesize..."),
|
| 33 |
gr.Dropdown(choices=LANGS, value="fr", label="Language"),
|
| 34 |
+
gr.Audio(label="Reference Audio (3-15 seconds)", type="filepath")
|
| 35 |
],
|
| 36 |
+
outputs=gr.Audio(label="Generated Speech"),
|
| 37 |
+
title="XTTS v2 Voice Cloning (CPU)",
|
| 38 |
+
description="Clone any voice from a 3-15 second audio sample. Supports 16 languages."
|
| 39 |
)
|
| 40 |
|
| 41 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|