ayymen commited on
Commit
f194fff
1 Parent(s): 884068b

Handle oov and sentence splitting

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -20,11 +20,12 @@ my_examples = [
20
 
21
  my_inputs = [
22
  gr.Textbox(lines=5, label="Input Text"),
 
23
  ]
24
 
25
  my_outputs = gr.Audio(type="filepath", label="Output Audio")
26
 
27
- def tts(text: str):
28
  best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
29
  config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
30
 
@@ -35,8 +36,14 @@ def tts(text: str):
35
  use_cuda=CUDA
36
  )
37
 
 
 
 
 
 
 
38
  # create audio file
39
- wavs = synthesizer.tts(text)
40
  with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
41
  synthesizer.save_wav(wavs, fp)
42
  return fp.name
 
20
 
21
  my_inputs = [
22
  gr.Textbox(lines=5, label="Input Text"),
23
+ gr.Checkbox(label="Split Sentences", value=True)
24
  ]
25
 
26
  my_outputs = gr.Audio(type="filepath", label="Output Audio")
27
 
28
+ def tts(text: str, split_sentences: bool = True):
29
  best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
30
  config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
31
 
 
36
  use_cuda=CUDA
37
  )
38
 
39
+ # replace oov characters
40
+ text = text.replace("\n", ". ")
41
+ text = text.replace("(", ",")
42
+ text = text.replace(")", ",")
43
+ text = text.replace(";", ",")
44
+
45
  # create audio file
46
+ wavs = synthesizer.tts(text, split_sentences=split_sentences)
47
  with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
48
  synthesizer.save_wav(wavs, fp)
49
  return fp.name