Example #1
0
    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 = ipa2mary("EISENBAHN", u"ˈaɪ̯zən̩ˌbaːn")
        #print "res: %s" % res
        self.assertEqual(res, "'aIz@nba:n")

        res = ipa2mary("DIPHTONGTEST", u"aɪɔɪaʊɜ'")
        #print "res: %s" % res
        self.assertEqual(res, "aIOIaUr='")
Example #2
0
    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ɲɑ̃")
        #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ʊɜ'")
        #print "res: %s" % res
        self.assertEqual(res, "aIOIaUr='")

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

        res = ipa2mary("RESTAURANT", u"ʁɛstɔʁɑ̃")
        #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~")
Example #3
0
    def synthesize(self, txt, mode='txt'):

        if self._host_tts == 'local':

            # import pdb; pdb.set_trace()

            wav = None

            if self.engine == 'mary':

                self.marytts.voice = self._voice
                self.marytts.locale = self._locale

                if mode == 'txt':
                    wav = self.marytts.synth_wav(txt)
                elif mode == 'ipa':
                    xs = ipa2mary('ipa', txt)
                    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':

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

                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')
            }
            url = 'http://%s:%s/tts/synth?%s' % (
                self._host_tts, self._port_tts, urllib.urlencode(args))

            response = requests.get(url)

            if response.status_code != 200:
                return None

            wav = response.content

        if wav:
            logging.debug('synthesize: %s %s -> WAV' % (txt, mode))
        else:
            logging.error('synthesize: %s %s -> NO WAV' % (txt, mode))

        return wav