Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#print "res: %s" % res
self.assertEqual (res, "REstORA~")
res = ipa2mary ("VIN", u"vɛ̃")
#print "res: %s" % res
self.assertEqual (res, "vE~")
res = ipa2mary ("BRUN", u"bʁœ̃")
#print "res: %s" % res
self.assertEqual (res, "bR9~")
res = ipa2mary ("POIGNANT", u"pwaɲɑ̃")
#print "res: %s" % res
self.assertEqual (res, "pwaJA~")
res = xsampa2ipa(u"entrée A~ t R e", u"A~ t R e")
#print "res: %s" % res
self.assertEqual (res, u"ɑ̃tʁe")
token = misc.edit_popup(stdscr, ' Token ', '')
lex_set_token (token)
# edit XS
elif c == ord('e'):
ipas = lex_entry['ipa']
xs = ipa2xsampa (lex_token, ipas, stress_to_vowels=False)
xs = misc.edit_popup(stdscr, ' X-SAMPA ', xs)
try:
ipas = xsampa2ipa (lex_token, xs)
lex_entry['ipa'] = ipas
except:
pass
#
# fini
#
curses.nocbreak(); stdscr.keypad(0); curses.echo()
curses.endwin()
lex.save()
tts.locale = 'en-US'
tts.engine = 'mary'
tts.voice = 'cmu-rms-hsmm'
tts.say_ipa(ipas, async=True)
# edit XS
elif resp.lower() == 'e':
ipas = lex_entry['ipa']
xs = ipa2xsampa (lex_token, ipas, stress_to_vowels=False)
readline.add_history(xs)
xs = raw_input(xs + '> ')
ipas = xsampa2ipa (lex_token, xs)
lex_entry['ipa'] = ipas
except:
logging.error('EXCEPTION CAUGHT %s' % traceback.format_exc())
lex.save()
print "new lexicon saved."
print
if self.host_tts == 'local':
if self.engine == 'mary':
mary_set_voice (self.voice)
mary_set_locale (self.locale)
mp = mary_gen_phonemes (word)
return mary2ipa(word, mp)
elif self.engine == 'espeak':
self.espeak.voice = self.voice
e_ipa = self.espeak.g2p (word, ipa='2')
xs = ipa2xsampa(word, e_ipa)
ipa = xsampa2ipa(word, xs)
logging.debug (u'espeak g2p: %s -> %s -> %s -> %s' % (word, e_ipa, xs, ipa))
return ipa
elif self.engine == 'sequitur':
if not self.voice in SEQUITUR_MODELS:
raise Exception ("no sequitur model for voice '%s'" % self.voice)
return sequitur_gen_ipa (SEQUITUR_MODELS[self.voice], word)
else:
raise Exception ("unknown engine '%s'" % self.engine)
if self._host_tts == 'local':
if self.engine == 'mary':
self.marytts.voice = self._voice
self.marytts.locale = self._locale
mp = self.marytts.g2p (word)
return mary2ipa(word, mp)
elif self.engine == 'espeak':
self.espeak.voice = self._voice
e_ipa = self.espeak.g2p (word, ipa='2')
xs = ipa2xsampa(word, e_ipa)
ipa = xsampa2ipa(word, xs)
logging.debug (u'espeak g2p: %s -> %s -> %s -> %s' % (word, e_ipa, xs, ipa))
return ipa
elif self.engine == 'sequitur':
if not self.voice in SEQUITUR_MODELS:
raise Exception ("no sequitur model for voice '%s'" % self.voice)
return sequitur_gen_ipa (SEQUITUR_MODELS[self.voice], word)
else:
raise Exception ("unknown engine '%s'" % self.engine)
stress = False
if ph[l-1]==u'0':
ph = ph[:l-1]
elif ph[l-1]==u'1':
ph = ph[:l-1]
stress = True
elif ph[l-1]==u'2':
ph = ph[:l-1]
# stress = True
if stress:
xs += u"'"
xs += CMU2XS[ph] + u' '
ipa = xsampa2ipa(word, xs)
# logging.debug(u'%s %s %s' % (word, xs, ipa))
logging.debug(u'%s %s' % (word, ipa))
lex_new[word] = ipa
if DEBUG_LIMIT and len(lex_new) >= DEBUG_LIMIT:
logging.warn('DEBUG LIMIT REACHED!')
break
# #
# # diff against existing dict
# #
#
# print "loading lexicon..."
# lex = Lexicon('dict-en.ipa')
readline.add_history(lex_token.encode('utf8'))
token = raw_input('token: ').decode('utf8')
lex_set_token (token)
# edit XS
elif c == 'e':
ipas = lex_entry['ipa']
xs = ipa2xsampa (lex_token, ipas, stress_to_vowels=False)
readline.add_history(xs.encode('utf8'))
xs = raw_input('X-SAMPA: ').decode('utf8')
ipas = xsampa2ipa (lex_token, xs)
lex_entry['ipa'] = ipas
except:
logging.error('EXCEPTION CAUGHT %s' % traceback.format_exc())
self.tts.locale = 'en-US'
self.tts.engine = 'mary'
self.tts.voice = 'cmu-rms-hsmm'
self.tts.say_ipa(ipas, async=True)
# edit XS
elif resp.lower() == 'e':
ipas = lex_entry['ipa']
xs = ipa2xsampa (lex_token, ipas, stress_to_vowels=False)
readline.add_history(xs)
xs = raw_input(xs + '> ')
ipas = xsampa2ipa (lex_token, xs)
lex_entry['ipa'] = ipas
except:
logging.error('EXCEPTION CAUGHT %s' % traceback.format_exc())
self.lex.save()
print "new lexicon saved."
print
def g2p(self, word):
res = self.translator(word)
xs = u' '.join(res)
ipa = xsampa2ipa(word, xs)
return ipa