hexgrad commited on
Commit
c27ca74
·
verified ·
1 Parent(s): e6e9674

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -110,26 +110,36 @@ VOCAB = get_vocab()
110
  def tokenize(ps):
111
  return [i for i in map(VOCAB.get, ps) if i is not None]
112
 
 
113
  CHOICES = {
114
- '🇺🇸 🚺 American Female 0': 'af_zero',
115
- '🇺🇸 🚺 Bella': 'af_bella',
116
- '🇺🇸 🚺 Nicole': 'af_nicole',
117
- '🇺🇸 🚹 Michael': 'am_michael',
118
- '🇺🇸 🚹 Adam': 'am_adam',
119
- '🇬🇧 🚺 British Female 0': 'bf_0',
120
- '🇬🇧 🚺 British Female 1': 'bf_1',
121
- '🇬🇧 🚺 British Female 2': 'bf_2',
122
- '🇬🇧 🚺 British Female 3': 'bf_3',
123
- '🇬🇧 🚹 British Male 0': 'bm_0',
124
- '🇬🇧 🚹 British Male 1': 'bm_1',
125
- '🇬🇧 🚹 British Male 2': 'bm_2',
126
- '🇯🇵 🚺 Japanese Female 0': 'jf_0',
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
  VOICES = {k: torch.load(os.path.join(snapshot, 'voices', f'{k}.pt'), weights_only=True).to(device) for k in CHOICES.values()}
129
- def get_random_af_voice():
130
- # Must be an American female voice to maintain compatability with
131
- # https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
132
- return random.choice(['af_zero', 'af_bella'])
133
 
134
  np_log_99 = np.log(99)
135
  def s_curve(p):
@@ -171,7 +181,8 @@ def forward(tokens, voice, speed):
171
 
172
  def generate(text, voice, ps=None, speed=1.0, reduce_noise=0.5, opening_cut=4000, closing_cut=2000, ease_in=3000, ease_out=1000, pad_before=5000, pad_after=5000):
173
  if voice not in VOICES:
174
- voice = get_random_af_voice()
 
175
  ps = ps or phonemize(text, voice)
176
  tokens = tokenize(ps)
177
  if not tokens:
@@ -210,7 +221,7 @@ with gr.Blocks() as basic_tts:
210
  with gr.Row():
211
  with gr.Column():
212
  text = gr.Textbox(label='Input Text')
213
- voice = gr.Dropdown(list(CHOICES.items()), label='Voice')
214
  with gr.Row():
215
  random_btn = gr.Button('Random Text', variant='secondary')
216
  generate_btn = gr.Button('Generate', variant='primary')
@@ -391,7 +402,7 @@ with gr.Blocks() as lf_tts:
391
  file_input = gr.File(file_types=['.pdf', '.txt'], label='Input File: pdf or txt')
392
  text = gr.Textbox(label='Input Text')
393
  file_input.upload(fn=extract_text, inputs=[file_input], outputs=[text])
394
- voice = gr.Dropdown(list(CHOICES.items()), label='Voice')
395
  with gr.Accordion('Text Settings', open=False):
396
  skip_square_brackets = gr.Checkbox(True, label='Skip [Square Brackets]', info='Recommended for academic papers, Wikipedia articles, or texts with citations.')
397
  newline_split = gr.Number(2, label='Newline Split', info='Split the input text on this many newlines. Affects how the text is segmented.', precision=0, minimum=0)
 
110
  def tokenize(ps):
111
  return [i for i in map(VOCAB.get, ps) if i is not None]
112
 
113
+ # 🧪 indicates that voices are experimental
114
  CHOICES = {
115
+ '🇺🇸 🚺 American Female 0': 'af_0',
116
+ '🇺🇸 🚺 Alloy 🧪': 'af_alloy',
117
+ '🇺🇸 🚺 Ava 🧪': 'af_ava',
118
+ '🇺🇸 🚺 Bella': 'af_bella',
119
+ '🇺🇸 🚺 Jessica 🧪': 'af_jessica',
120
+ '🇺🇸 🚺 Nicole': 'af_nicole',
121
+ '🇺🇸 🚺 Nova 🧪': 'af_nova',
122
+ '🇺🇸 🚺 River 🧪': 'af_river',
123
+ '🇺🇸 🚺 Sarah': 'af_sarah',
124
+ '🇺🇸 🚺 Sky 🧪': 'af_sky',
125
+ '🇺🇸 🚹 Adam': 'am_adam',
126
+ '🇺🇸 🚹 Echo 🧪': 'am_echo',
127
+ '🇺🇸 🚹 Eric 🧪': 'am_eric',
128
+ '🇺🇸 🚹 Liam 🧪': 'am_liam',
129
+ '🇺🇸 🚹 Michael': 'am_michael',
130
+ '🇺🇸 🚹 Onyx 🧪': 'am_onyx',
131
+ '🇬🇧 🚺 British Female 0': 'bf_0',
132
+ '🇬🇧 🚺 Alice 🧪': 'bf_alice',
133
+ '🇬🇧 🚺 Lily 🧪': 'bf_lily',
134
+ '🇬🇧 🚹 British Male 0': 'bm_0',
135
+ '🇬🇧 🚹 British Male 1': 'bm_1',
136
+ '🇬🇧 🚹 British Male 2': 'bm_2',
137
+ '🇬🇧 🚹 Daniel 🧪': 'bm_daniel',
138
+ '🇬🇧 🚹 Fable 🧪': 'bm_fable',
139
+ '🇬🇧 🚹 George 🧪': 'bm_george',
140
+ '🇯🇵 🚺 Japanese Female 0': 'jf_0',
141
  }
142
  VOICES = {k: torch.load(os.path.join(snapshot, 'voices', f'{k}.pt'), weights_only=True).to(device) for k in CHOICES.values()}
 
 
 
 
143
 
144
  np_log_99 = np.log(99)
145
  def s_curve(p):
 
181
 
182
  def generate(text, voice, ps=None, speed=1.0, reduce_noise=0.5, opening_cut=4000, closing_cut=2000, ease_in=3000, ease_out=1000, pad_before=5000, pad_after=5000):
183
  if voice not in VOICES:
184
+ # Ensure stability for https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
185
+ voice = 'af_0'
186
  ps = ps or phonemize(text, voice)
187
  tokens = tokenize(ps)
188
  if not tokens:
 
221
  with gr.Row():
222
  with gr.Column():
223
  text = gr.Textbox(label='Input Text')
224
+ voice = gr.Dropdown(list(CHOICES.items()), label='Voice', info='🧪 Experimental voices may be unstable.')
225
  with gr.Row():
226
  random_btn = gr.Button('Random Text', variant='secondary')
227
  generate_btn = gr.Button('Generate', variant='primary')
 
402
  file_input = gr.File(file_types=['.pdf', '.txt'], label='Input File: pdf or txt')
403
  text = gr.Textbox(label='Input Text')
404
  file_input.upload(fn=extract_text, inputs=[file_input], outputs=[text])
405
+ voice = gr.Dropdown(list(CHOICES.items()), label='Voice', info='🧪 Experimental voices may be unstable.')
406
  with gr.Accordion('Text Settings', open=False):
407
  skip_square_brackets = gr.Checkbox(True, label='Skip [Square Brackets]', info='Recommended for academic papers, Wikipedia articles, or texts with citations.')
408
  newline_split = gr.Number(2, label='Newline Split', info='Split the input text on this many newlines. Affects how the text is segmented.', precision=0, minimum=0)