mrfakename commited on
Commit
c1d7434
1 Parent(s): c86b5aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -1,6 +1,10 @@
1
  import gradio as gr
2
  from collections.abc import Iterable
3
  from gruut import sentences
 
 
 
 
4
  import phonemizer
5
  global_phonemizer = phonemizer.backend.EspeakBackend(language='en-us', preserve_punctuation=True, with_stress=True, words_mismatch='ignore')
6
  from nltk import word_tokenize
@@ -32,6 +36,10 @@ def gruut(text):
32
  phonemized.append(word.phonemes)
33
  phonemized_text = ' '.join(phonemized)
34
  return phonemized_text
 
 
 
 
35
  def phonemizerfunc(text):
36
  text = text.strip()
37
  text = text.replace('"', '')
@@ -46,10 +54,13 @@ def run(t, r):
46
  if r == 'phonemizer': return phonemizerfunc(t)
47
  if r == 'gruut': return gruut(t)
48
  if r == 'deep_phonemizer': return dp(t)
 
 
 
49
  with gr.Blocks() as demo:
50
  gr.Markdown("# PhonemizerHub")
51
  t = gr.Textbox(label="Text", placeholder="Enter text...", interactive=True)
52
- r = gr.Radio(choices=['phonemizer', 'gruut', 'deep_phonemizer'], value='phonemizer', interactive=True, label='Select a phonemizer')
53
  b = gr.Button("Phonemize")
54
  out = gr.Textbox(interactive=True, label="Phonemes")
55
  b.click(run, inputs=[t, r], outputs=[out])
 
1
  import gradio as gr
2
  from collections.abc import Iterable
3
  from gruut import sentences
4
+ from phonemap.g2pphonemizer import G2PPhonemizer
5
+ from phonemap.charsiu import CharsiuPhonemizer
6
+ g2p = G2PPhonemizer()
7
+ charsiu = CharsiuPhonemizer()
8
  import phonemizer
9
  global_phonemizer = phonemizer.backend.EspeakBackend(language='en-us', preserve_punctuation=True, with_stress=True, words_mismatch='ignore')
10
  from nltk import word_tokenize
 
36
  phonemized.append(word.phonemes)
37
  phonemized_text = ' '.join(phonemized)
38
  return phonemized_text
39
+ def g2pen(text):
40
+ return g2p.phonemize(text)
41
+ def docharsiu(text):
42
+ return charsiu.phonemize(text)
43
  def phonemizerfunc(text):
44
  text = text.strip()
45
  text = text.replace('"', '')
 
54
  if r == 'phonemizer': return phonemizerfunc(t)
55
  if r == 'gruut': return gruut(t)
56
  if r == 'deep_phonemizer': return dp(t)
57
+ if r == 'g2p_en': return g2pen(t)
58
+ if r == 'charsiu (slow)': return docharsiu(t)
59
+ return f'Error: Phonemizer {r} not found, please try another Phonemizer and create a Community discussion on HF.'
60
  with gr.Blocks() as demo:
61
  gr.Markdown("# PhonemizerHub")
62
  t = gr.Textbox(label="Text", placeholder="Enter text...", interactive=True)
63
+ r = gr.Radio(choices=['phonemizer', 'gruut', 'deep_phonemizer', 'g2p_en', 'charsiu (slow)'], value='phonemizer', interactive=True, label='Select a phonemizer')
64
  b = gr.Button("Phonemize")
65
  out = gr.Textbox(interactive=True, label="Phonemes")
66
  b.click(run, inputs=[t, r], outputs=[out])