tykiww commited on
Commit
3a4510f
·
verified ·
1 Parent(s): aca53ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -3,6 +3,8 @@ from TTS.api import TTS
3
  import gradio as gr
4
  import os
5
  import spaces
 
 
6
 
7
  #inference:
8
  # file_path: "output.wav"
@@ -10,42 +12,49 @@ import spaces
10
  # language: "en"
11
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Agree to Terms of service
15
  # os.environ["COQUI_TOS_AGREED"] = "1"
16
 
17
- def init_TTS():
18
  # Get device
19
  device = "cuda" if torch.cuda.is_available() else "cpu"
20
  # Initialize the TTS model
21
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
22
  return tts
23
 
24
 
25
  @spaces.GPU
26
- def generate_speech(text):
27
  # Generate speech using the provided text, speaker voice, and language
28
- file_path = "output.wav"
29
- speaker_wav = "content/speaker.wav"
30
- language = "en"
31
  tts.tts_to_file(text=text,
32
- file_path=file_path,
33
- speaker_wav=speaker_wav,
34
- language=language)
35
  return file_path
36
 
37
 
38
 
39
- def main():
40
-
41
- # call init
42
- tts = init_TTS()
43
 
44
  # Create the Gradio interface
45
  interface = gr.Interface(
46
  fn=generate_speech,
47
  inputs=[
48
- gr.Textbox(label="Enter your text")
 
49
  #gr.Textbox(label="Path to target speaker WAV file", value="/content/speaker.wav")
50
  #gr.Dropdown(label="Language", choices=["en"], value="en")
51
  ],
@@ -59,7 +68,11 @@ def main():
59
  return 0
60
 
61
  if __name__ == "__main__":
62
- main()
 
 
 
 
63
 
64
 
65
 
 
3
  import gradio as gr
4
  import os
5
  import spaces
6
+ import yaml
7
+
8
 
9
  #inference:
10
  # file_path: "output.wav"
 
12
  # language: "en"
13
 
14
 
15
+ def get_config():
16
+ # get config path
17
+ config_path = os.environ["CONFIG_PATH"]
18
+ # Parse the YAML file
19
+ with open(config_path, 'r') as file:
20
+ config = yaml.safe_load(file)
21
+
22
+ print(config['inference'])
23
+ print(config_path)
24
+ return config
25
+
26
+
27
 
28
  # Agree to Terms of service
29
  # os.environ["COQUI_TOS_AGREED"] = "1"
30
 
31
+ def init_TTS(config):
32
  # Get device
33
  device = "cuda" if torch.cuda.is_available() else "cpu"
34
  # Initialize the TTS model
35
+ tts = TTS(config['inference']['model']).to(device)
36
  return tts
37
 
38
 
39
  @spaces.GPU
40
+ def generate_speech(text, config):
41
  # Generate speech using the provided text, speaker voice, and language
 
 
 
42
  tts.tts_to_file(text=text,
43
+ file_path=config['inference']['file_path'],
44
+ speaker_wav=config['inference']['speaker_wav'],
45
+ language=config['inference']['language'])
46
  return file_path
47
 
48
 
49
 
50
+ def main(config):
 
 
 
51
 
52
  # Create the Gradio interface
53
  interface = gr.Interface(
54
  fn=generate_speech,
55
  inputs=[
56
+ gr.Textbox(label="Enter your text"),
57
+ config
58
  #gr.Textbox(label="Path to target speaker WAV file", value="/content/speaker.wav")
59
  #gr.Dropdown(label="Language", choices=["en"], value="en")
60
  ],
 
68
  return 0
69
 
70
  if __name__ == "__main__":
71
+ # Get config
72
+ config = get_config()
73
+ # initialize TTS
74
+ tts = init_TTS(config)
75
+ main(config)
76
 
77
 
78