don0726 commited on
Commit
a8bbd3d
·
verified ·
1 Parent(s): cda18dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -1,13 +1,44 @@
 
 
1
  import gradio as gr
 
2
 
3
- def test_api(text):
4
- return f"You sent: {text}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  demo = gr.Interface(
7
- fn=test_api,
8
- inputs=gr.Textbox(label="Text"),
9
- outputs=gr.Textbox(label="Output"),
10
- api_name="test"
 
 
 
11
  )
12
 
13
  demo.queue()
 
1
+ import os
2
+ import tempfile
3
  import gradio as gr
4
+ from TTS.api import TTS
5
 
6
+ os.environ["COQUI_TOS_AGREED"] = "1"
7
+
8
+
9
+ print("🔁 Loading XTTS model once...")
10
+
11
+ tts = TTS(
12
+ model_path="/models/xtts/",
13
+ config_path="/models/xtts/config.json",
14
+ gpu=False
15
+ )
16
+
17
+ print("✅ Model loaded!")
18
+
19
+ def tts_api(text, speaker_wav):
20
+ if not text or speaker_wav is None:
21
+ raise gr.Error("Please provide text and speaker audio.")
22
+
23
+ out_path = os.path.join(tempfile.gettempdir(), "out.wav")
24
+
25
+ tts.tts_to_file(
26
+ text=text,
27
+ speaker_wav=speaker_wav,
28
+ language="en",
29
+ file_path=out_path
30
+ )
31
+
32
+ return out_path
33
 
34
  demo = gr.Interface(
35
+ fn=tts_api,
36
+ inputs=[
37
+ gr.Textbox(label="Text"),
38
+ gr.Audio(type="filepath", label="Speaker WAV"),
39
+ ],
40
+ outputs=gr.Audio(type="filepath", label="Output Audio"),
41
+ api_name="tts"
42
  )
43
 
44
  demo.queue()