AntonioMS commited on
Commit
5e5e671
1 Parent(s): 52ff052

Cambio app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
app.py CHANGED
@@ -5,50 +5,42 @@ import gradio as gr
5
  import numpy as np
6
  from TTS.utils.manage import ModelManager
7
  from TTS.utils.synthesizer import Synthesizer
 
8
 
9
 
10
- MODELS = {}
11
- SPEAKERS = {}
12
- MAX_TXT_LEN = 100
13
-
14
-
15
- manager = ModelManager()
16
- MODEL_NAMES = manager.list_tts_models()
17
-
18
- # filter out multi-speaker models and slow wavegrad vocoders
19
- filters = ["vctk", "your_tts", "ek1"]
20
- MODEL_NAMES = [model_name for model_name in MODEL_NAMES if not any(f in model_name for f in filters)]
21
-
22
- EN = [el for el in MODEL_NAMES if "/en/" in el]
23
- OTHER = [el for el in MODEL_NAMES if "/en/" not in el]
24
- EN[0], EN[5] = EN[5], EN[0]
25
- MODEL_NAMES = EN + OTHER
26
 
27
  # reorder models
28
  print(MODEL_NAMES)
29
 
30
 
31
- def tts(text: str, model_name: str):
32
- if len(text) > MAX_TXT_LEN:
33
- text = text[:MAX_TXT_LEN]
34
- print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
35
- print(text, model_name)
36
- # download model
37
- model_path, config_path, model_item = manager.download_model(model_name)
38
- vocoder_name: Optional[str] = model_item["default_vocoder"]
39
- # download vocoder
 
 
 
 
 
 
 
40
  vocoder_path = None
41
  vocoder_config_path = None
42
- if vocoder_name is not None:
43
- vocoder_path, vocoder_config_path, _ = manager.download_model(vocoder_name)
44
- # init synthesizer
45
  synthesizer = Synthesizer(
46
- model_path, config_path, None, None, vocoder_path, vocoder_config_path,
47
  )
 
48
  # synthesize
49
  if synthesizer is None:
50
  raise NameError("model not found")
51
- wavs = synthesizer.tts(text, None)
52
  # return output
53
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
54
  synthesizer.save_wav(wavs, fp)
 
5
  import numpy as np
6
  from TTS.utils.manage import ModelManager
7
  from TTS.utils.synthesizer import Synthesizer
8
+ import os
9
 
10
 
11
+ MODEL_NAMES = ["Celtia", "Icia", "Sabela"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # reorder models
14
  print(MODEL_NAMES)
15
 
16
 
17
+ def tts(text: str,
18
+ model_file: str = "icia.pth"
19
+ ):
20
+
21
+ model_path = os.path.join(os.getcwd(), model_file)
22
+ # if text is "celtia" take celtia.pth and celtia_config.json
23
+ if text == "Celtia":
24
+ config_path = "celtia_config.json"
25
+ model_file = "celtia.pth"
26
+ elif text == "Icia":
27
+ config_path = "icia_config.json"
28
+ model_file = "icia.pth"
29
+ else:
30
+ config_path = "sabela_config.json"
31
+ model_file = "sabela.pth"
32
+
33
  vocoder_path = None
34
  vocoder_config_path = None
35
+
 
 
36
  synthesizer = Synthesizer(
37
+ model_path, config_path, None, vocoder_path, vocoder_config_path,
38
  )
39
+
40
  # synthesize
41
  if synthesizer is None:
42
  raise NameError("model not found")
43
+ wavs = synthesizer.tts(text)
44
  # return output
45
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
46
  synthesizer.save_wav(wavs, fp)