mrfakename commited on
Commit
8ee2458
·
verified ·
1 Parent(s): 780ce95

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gruut import sentences
3
+ import phonemizer
4
+ global_phonemizer = phonemizer.backend.EspeakBackend(language='en-us', preserve_punctuation=True, with_stress=True, words_mismatch='ignore')
5
+ from nltk import word_tokenize
6
+ import nltk
7
+ from cached_path import cached_path
8
+
9
+ from dp.phonemizer import Phonemizer
10
+ phonemizer = Phonemizer.from_checkpoint(str(cached_path('https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt')))
11
+
12
+
13
+ nltk.download('punkt')
14
+ # Borrowed from https://github.com/sidharthrajaram/StyleTTS2/blob/main/src/styletts2/phoneme.py, MIT License
15
+ def gruut(text):
16
+ phonemized = []
17
+ for sent in sentences(text, lang='en-us'):
18
+ for word in sent:
19
+ if isinstance(word.phonemes, Iterable):
20
+ phonemized.append(''.join(word.phonemes))
21
+ elif isinstance(word.phonemes, str):
22
+ phonemized.append(word.phonemes)
23
+ phonemized_text = ' '.join(phonemized)
24
+ return phonemized_text
25
+ def phonemizer(text):
26
+ text = text.strip()
27
+ text = text.replace('"', '')
28
+ ps = global_phonemizer.phonemize([text])
29
+ ps = word_tokenize(ps[0])
30
+ ps = ' '.join(ps)
31
+ return ps
32
+ def dp(text):
33
+ return phonemizer(text, lang='en_us')
34
+
35
+ with gr.Blocks() as demo:
36
+ pass
37
+ demo.queue().launch()