Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,37 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
from TTS.api import TTS
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 7 |
|
| 8 |
print("🔁 Loading XTTS model once...")
|
| 9 |
|
| 10 |
tts = TTS(
|
| 11 |
-
|
|
|
|
| 12 |
gpu=False
|
| 13 |
)
|
| 14 |
|
| 15 |
print("✅ Model loaded!")
|
| 16 |
|
| 17 |
def generate(text, speaker_wav):
|
| 18 |
-
out_path = "
|
|
|
|
| 19 |
tts.tts_to_file(
|
| 20 |
text=text,
|
| 21 |
speaker_wav=speaker_wav,
|
| 22 |
-
language="
|
| 23 |
file_path=out_path
|
| 24 |
)
|
| 25 |
return out_path
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
btn.click(generate, inputs=[text, wav], outputs=out)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
|
|
|
| 5 |
|
| 6 |
print("🔁 Loading XTTS model once...")
|
| 7 |
|
| 8 |
tts = TTS(
|
| 9 |
+
model_path="/models/xtts/model.pth",
|
| 10 |
+
config_path="/models/xtts/config.json",
|
| 11 |
gpu=False
|
| 12 |
)
|
| 13 |
|
| 14 |
print("✅ Model loaded!")
|
| 15 |
|
| 16 |
def generate(text, speaker_wav):
|
| 17 |
+
out_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name
|
| 18 |
+
|
| 19 |
tts.tts_to_file(
|
| 20 |
text=text,
|
| 21 |
speaker_wav=speaker_wav,
|
| 22 |
+
language="en",
|
| 23 |
file_path=out_path
|
| 24 |
)
|
| 25 |
return out_path
|
| 26 |
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=generate,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr.Textbox(label="Text"),
|
| 31 |
+
gr.Audio(type="filepath", label="Speaker Sample (wav)")
|
| 32 |
+
],
|
| 33 |
+
outputs=gr.Audio(label="Generated Voice")
|
| 34 |
+
)
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
demo.launch()
|