Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,32 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
from TTS.api import TTS
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
CONFIG_PATH = "/models/xtts/config.json"
|
| 7 |
-
|
| 8 |
-
print("🔁 Loading XTTS model once...")
|
| 9 |
|
| 10 |
tts = TTS(
|
| 11 |
-
model_path=
|
| 12 |
-
config_path=
|
| 13 |
gpu=False
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def generate_tts(text, speaker_wav):
|
| 19 |
-
if not text or speaker_wav is None:
|
| 20 |
-
return None
|
| 21 |
-
|
| 22 |
-
out_path = "output.wav"
|
| 23 |
-
|
| 24 |
tts.tts_to_file(
|
| 25 |
text=text,
|
| 26 |
speaker_wav=speaker_wav,
|
| 27 |
-
|
| 28 |
-
|
| 29 |
)
|
| 30 |
-
|
| 31 |
return out_path
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
fn=generate_tts,
|
| 36 |
inputs=[
|
| 37 |
gr.Textbox(label="Text"),
|
| 38 |
-
gr.Audio(type="filepath", label="
|
| 39 |
],
|
| 40 |
-
outputs=gr.Audio(type="filepath"
|
| 41 |
-
title="XTTS Voice Cloning (CPU)",
|
| 42 |
-
description="Upload voice + text → get cloned speech"
|
| 43 |
)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
| 1 |
from TTS.api import TTS
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
MODEL_DIR = "/models/xtts"
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
tts = TTS(
|
| 8 |
+
model_path=f"{MODEL_DIR}/model.pth",
|
| 9 |
+
config_path=f"{MODEL_DIR}/config.json",
|
| 10 |
gpu=False
|
| 11 |
)
|
| 12 |
|
| 13 |
+
def synthesize(text, speaker_wav):
|
| 14 |
+
out_path = "/tmp/out.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
tts.tts_to_file(
|
| 16 |
text=text,
|
| 17 |
speaker_wav=speaker_wav,
|
| 18 |
+
file_path=out_path,
|
| 19 |
+
language="en"
|
| 20 |
)
|
|
|
|
| 21 |
return out_path
|
| 22 |
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=synthesize,
|
|
|
|
| 25 |
inputs=[
|
| 26 |
gr.Textbox(label="Text"),
|
| 27 |
+
gr.Audio(type="filepath", label="Voice Sample (10–30 sec)"),
|
| 28 |
],
|
| 29 |
+
outputs=gr.Audio(type="filepath"),
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|