How to use the nltools.phonetics.ipa2xsampa function in nltools

To help you get started, we’ve selected a few nltools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gooofy / py-nltools / tests / test_phonetics.py View on Github external
def test_ipa(self):

        res = ipa2xsampa ("EISENBAHN", u"ˈaɪ̯zən̩ˌbaːn")
        #print "res: %s" % res
        self.assertEqual (res, "'aIz@nba:n")

        res = ipa2xsampa ("DIPHTONGTEST", u"aɪɔɪaʊɜ'")
        #print "res: %s" % res
        self.assertEqual (res, "aIOIaU3")

        res = ipa2xsampa ("BON", u"bɔ̃")
        #print "res: %s" % res
        self.assertEqual (res, "bO~")

        res = ipa2xsampa ("RESTAURANT", u"ʁɛstɔʁɑ̃")
        #print "res: %s" % res
        self.assertEqual (res, "REstORA~")

        res = ipa2xsampa ("VIN", u"vɛ̃")
        #print "res: %s" % res
        self.assertEqual (res, "vE~")

        res = ipa2xsampa ("BRUN", u"bʁœ̃")
        #print "res: %s" % res
        self.assertEqual (res, "bR9~")

        res = ipa2xsampa ("POIGNANT", u"pwaɲɑ̃")
github gooofy / py-nltools / tests / test_phonetics.py View on Github external
#print "res: %s" % res
        self.assertEqual (res, "'aIz@nba:n")

        res = ipa2xsampa ("DIPHTONGTEST", u"aɪɔɪaʊɜ'")
        #print "res: %s" % res
        self.assertEqual (res, "aIOIaU3")

        res = ipa2xsampa ("BON", u"bɔ̃")
        #print "res: %s" % res
        self.assertEqual (res, "bO~")

        res = ipa2xsampa ("RESTAURANT", u"ʁɛstɔʁɑ̃")
        #print "res: %s" % res
        self.assertEqual (res, "REstORA~")

        res = ipa2xsampa ("VIN", u"vɛ̃")
        #print "res: %s" % res
        self.assertEqual (res, "vE~")

        res = ipa2xsampa ("BRUN", u"bʁœ̃")
        #print "res: %s" % res
        self.assertEqual (res, "bR9~")

        res = ipa2xsampa ("POIGNANT", u"pwaɲɑ̃")
        #print "res: %s" % res
        self.assertEqual (res, "pwaJA~")

        res = ipa2mary ("EISENBAHN", u"ˈaɪ̯zən̩ˌbaːn")
        #print "res: %s" % res
        self.assertEqual (res, "'aIz@nba:n")

        res = ipa2mary ("DIPHTONGTEST", u"aɪɔɪaʊɜ'")
github gooofy / zamia-speech / speech_sphinx_export.py View on Github external
phoneset = set()

    pdfn = '%s/etc/voxforge.dic' % work_dir
    with codecs.open (pdfn, 'w', 'utf8') as pdf:

        for word in lex:

            if ENABLE_NOISE_FILLER:
                if word == NOISE_WORD:
                    logging.debug ('skipping noise word')
                    continue

            ipa = lex[word]['ipa']

            xs  = ipa2xsampa(word, ipa)
            xa  = xsampa2xarpabet(word, xs)

            pdf.write (u'%s %s\n' % (word, xa))

            phones = xa.split(' ')
            for phone in phones:

                if len(phone.strip()) == 0:
                    logging.error(u"***ERROR: empty phone detected in lex entry %s %s" % (word, ipa))

                phoneset.add(phone)
        
    logging.info("%s written." % pdfn)

    logging.info("Got %d phones." % len(phoneset))
github gooofy / py-nltools / nltools / tts_client.py View on Github external
wav = mary_synth (txt)
                elif mode == 'ipa':
                    xs = ipa2mary ('ipa', txt)
                    wav = mary_synth_phonemes (xs)
                else:
                    raise Exception ("unknown mary mode '%s'" % mode)

            elif self.engine == 'espeak':

                if mode == 'txt':

                    self.espeak.voice = self.voice
                    wav = self.espeak.synth_wav (txt)

                elif mode == 'ipa':
                    xs = ipa2xsampa ('ipa', txt)
                    logging.debug ('synthesize: %s %s -> %s' % (txt, mode, repr(xs)))
                    wav = self.espeak.synth_wav (xs, fmt='xs')

                else:
                    raise Exception ("unknown espeak mode '%s'" % mode)
            else:

                raise Exception ("unknown engine '%s'" % self.engine)

        else:

            args = {'l': self.locale,
                    'v': self.voice,
                    'e': self.engine,
                    'm': mode,
                    't': txt.encode('utf8')}
github gooofy / zamia-speech / wav2letter_export.py View on Github external
covered_by_lex = False
                break

        if not covered_by_lex:
            continue

        with codecs.open('%s/%09d.id'  % (destdirfn, utt_num[train_val]), 'w', 'utf8') as idf,   \
             codecs.open('%s/%09d.tkn' % (destdirfn, utt_num[train_val]), 'w', 'utf8') as tknf,  \
             codecs.open('%s/%09d.wrd' % (destdirfn, utt_num[train_val]), 'w', 'utf8') as wrdf   :

            tkn = u''
            wrd = u''
            for token in tokens:

                ipas = lex[token]['ipa'] 
                xsr = ipa2xsampa(token, ipas, spaces=True)

                xs = (xsr.replace('-', '')
                         .replace('\' ', '\'')
                         .replace('  ', ' ')
                         .replace('#', 'nC'))

                if tkn:
                    tkn += u' | '
                    wrd += u' '

                tkn += xs
                wrd += token
                
            tknf.write('%s\n' % tkn)
            wrdf.write('%s\n' % wrd)
            idf.write('utt_id\t%s\ncorpus\t%s\nlang\t%s\n' % (utt_id, ts['corpus_name'], options.lang))
github gooofy / py-nltools / nltools / tts.py View on Github external
wav = self.marytts.synth_wav (xs, fmt='xs')
                else:
                    raise Exception ("unknown mary mode '%s'" % mode)

            elif self.engine == 'espeak':

                if mode == 'txt':

                    self.espeak.voice = self._voice
                    self.espeak.speed = self._speed
                    self.espeak.pitch = self._pitch
                    wav = self.espeak.synth_wav (txt)
                    # logging.debug ('synthesize: %s %s -> %s' % (txt, mode, repr(wav)))

                elif mode == 'ipa':
                    xs = ipa2xsampa ('ipa', txt)
                    logging.debug ('synthesize: %s %s -> %s' % (txt, mode, repr(xs)))
                    wav = self.espeak.synth_wav (xs, fmt='xs')

            elif self.engine == 'pico':

                if mode == 'txt':

                    if not self.picotts:
                        from picotts import PicoTTS
                        self.picotts = PicoTTS()

                    self.picotts.voice = self._voice
                    wav = self.picotts.synth_wav (txt)
                    # logging.debug ('synthesize: %s %s -> %s' % (txt, mode, repr(wav)))

                else:
github gooofy / zamia-speech / lex_edit.py View on Github external
elif resp.lower() == 'u':
            
                    ipas = lex_entry['ipa']

                    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
github gooofy / py-nltools / nltools / tts.py View on Github external
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)
github gooofy / zamia-speech / abook-transcribe.py View on Github external
elif resp.lower() == 'u':
        
                ipas = lex_entry['ipa']

                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