def cmu2ipa(tok): import lexconvert res=lexconvert.convert(tok,'cmu','unicode-ipa-syls') ## BUG FIXES if tok.endswith(' T') and not res.endswith('t'): res=res+'t' return res
def cmu2ipa(tok): import lexconvert res=lexconvert.convert(str(tok),'cmu','unicode-ipa') ## BUG FIXES if tok.endswith(' T') and not res.endswith('t'): res=res+'t' return res
def init_run_mary(self,text): import lexconvert,bs4 numwords = 0 stanza=self.newchild() line=stanza.newchild() for stanzatext in text.split('\n\n'): stanzatext=stanzatext.strip() if not stanzatext: continue for linetext in stanzatext.split('\n'): linetext=linetext.strip() if not linetext: continue wordlist=linetext.split() for i,word in enumerate(wordlist): p0,word,p1=gleanPunc2(word) if p0 and not line.empty(): line.finish() if not word: continue if stanza.finished: stanza = self.newchild() if line.finished: line = stanza.newchild() if self.dict.has(word): words=self.dict.get(word) for w in words: w.origin='cmu' else: ## make word from openmary wordxml=bs4.BeautifulSoup(openmary(word)) sylls=[] for syll in wordxml.find_all('syllable'): syllstr="'" if syll.get('stress',None) else "" syllstr+=lexconvert.convert(syll['ph'],'x-sampa','unicode-ipa') sylls+=[syllstr] from Phoneme import Phoneme if len(sylls)>1 and not True in [Phoneme(phon).isVowel() for phon in sylls[0]]: sylls=[sylls[0]+sylls[1]]+ (sylls[2:] if len(sylls)>2 else []) pronounc='.'.join(sylls) words=[ self.dict.make((pronounc,[]), word) ] for w in words: w.origin='openmary' line.newchild(words) if p1 and not line.empty(): line.finish() numwords+=1 if not line.empty(): line.finish() if not line.empty(): line.finish() if not stanza.empty(): stanza.finish()
def sampa2ipa(sampa): import lexconvert if sampa == 'r=': return u'ɛː' return lexconvert.convert(sampa, 'x-sampa', 'unicode-ipa') sampa = sampa.replace(u'?', u'') if not sampa: return sampa if ':' in sampa: colon = u'ː' sampa = sampa.replace(u':', u'') else: colon = u'' if not sampa in d_sampa2ipa and len(sampa) == 2: #print "?!!",sampa return sampa2ipa(sampa[0]) + sampa2ipa(sampa[1]) else: return d_sampa2ipa[sampa] + colon
def sampa2ipa(sampa): import lexconvert if sampa == 'r=': return u'ɛː' return lexconvert.convert(sampa,'x-sampa','unicode-ipa') sampa=sampa.replace(u'?',u'') if not sampa: return sampa if ':' in sampa: colon=u'ː' sampa=sampa.replace(u':',u'') else: colon=u'' if not sampa in d_sampa2ipa and len(sampa)==2: #print "?!!",sampa return sampa2ipa(sampa[0]) + sampa2ipa(sampa[1]) else: return d_sampa2ipa[sampa] + colon
def ipa2cmu(tok): import lexconvert return lexconvert.convert(str(tok),'unicode-ipa','cmu')
def espeak2cmu(tok): import lexconvert return lexconvert.convert(str(tok),'espeak','cmu')
def cmu2ipa(tok): import lexconvert return lexconvert.convert(tok, 'cmu', 'unicode-ipa')
def ipa2cmu(tok): import lexconvert return lexconvert.convert(tok,'unicode-ipa','cmu')
def espeak2cmu(tok): import lexconvert return lexconvert.convert(tok,'espeak','cmu')
def cmu2ipa(tok): import lexconvert return lexconvert.convert(tok,'cmu','unicode-ipa')