tykiww commited on
Commit
4af5dfa
·
verified ·
1 Parent(s): 45fac78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
app.py CHANGED
@@ -7,14 +7,14 @@ import spaces
7
 
8
 
9
  # Agree to Terms of service
10
- os.environ["COQUI_TOS_AGREED"] = "1"
11
-
12
- # Get device
13
- device = "cuda" if torch.cuda.is_available() else "cpu"
14
-
15
- # Initialize the TTS model
16
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
17
 
 
 
 
 
 
 
18
 
19
 
20
  @spaces.GPU
@@ -29,19 +29,33 @@ def generate_speech(text):
29
  language=language)
30
  return file_path
31
 
32
- # Create the Gradio interface
33
- interface = gr.Interface(
34
- fn=generate_speech,
35
- inputs=[
36
- gr.Textbox(label="Enter your text")
37
- #gr.Textbox(label="Path to target speaker WAV file", value="/content/speaker.wav")
38
- #gr.Dropdown(label="Language", choices=["en"], value="en")
39
- ],
40
- outputs="audio",
41
- title="Voice Synthesis with Coqui-XTTS",
42
- description="Synthesize speech using predefined target voice and language."
43
- )
44
- # Launch the interface
45
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
 
 
7
 
8
 
9
  # Agree to Terms of service
10
+ # os.environ["COQUI_TOS_AGREED"] = "1"
 
 
 
 
 
 
11
 
12
+ def init_TTS():
13
+ # Get device
14
+ device = "cuda" if torch.cuda.is_available() else "cpu"
15
+ # Initialize the TTS model
16
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
17
+ return tts
18
 
19
 
20
  @spaces.GPU
 
29
  language=language)
30
  return file_path
31
 
32
+
33
+
34
+ def main():
35
+
36
+ # call init
37
+ tts = init_TTS()
38
+
39
+ # Create the Gradio interface
40
+ interface = gr.Interface(
41
+ fn=generate_speech,
42
+ inputs=[
43
+ gr.Textbox(label="Enter your text")
44
+ #gr.Textbox(label="Path to target speaker WAV file", value="/content/speaker.wav")
45
+ #gr.Dropdown(label="Language", choices=["en"], value="en")
46
+ ],
47
+ outputs="audio",
48
+ title="Voice Synthesis with Coqui-XTTS",
49
+ description="Synthesize speech using predefined target voice and language."
50
+ )
51
+
52
+ # Launch the interface
53
+ interface.launch()
54
+ return 0
55
+
56
+ if __name__ == "__main__":
57
+ main()
58
+
59
+
60
 
61