Esempio n. 1
0
    def _tts(self, text):
        try:
            with open(self.script, 'w') as f:
                f.write("""
(voice_{voice})
(set! utt1 (Utterance Text "{text}"))
(utt.synth utt1)
(utt.save.segs utt1 "{timingfile}")
(utt.save.wave utt1 "{audiofile}")""".format(
                    voice=self.params['voice'],
                    text=text, timingfile=self.timing, audiofile=self.wavout)
                )
            subprocess.Popen(
                ['festival', '-b', self.script], stdout=subprocess.PIPE,
                stderr=subprocess.PIPE).communicate()
        except Exception as ex:
            import traceback
            logger.error('TTS error: {}'.format(traceback.format_exc()))
            return

        tts_data = TTSData()
        tts_data.wavout = self.wavout
        tts_data.phonemes = self.get_phonemes()
        tts_data.visemes = self.viseme_config.get_visemes(tts_data.phonemes)

        os.remove(self.timing)
        os.remove(self.script)
        return tts_data
Esempio n. 2
0
 def _tts(self, text):
     params = {
         "INPUT_TEXT": text,
     }
     params.update(self.params)
     response = requests.get('{}/process'.format(self.url), params=params)
     if response.status_code != 200:
         raise RuntimeError("{}".format(response.status_code))
     with open(self.wavout, 'wb') as f:
         f.write(response.content)
     tts_data = TTSData()
     tts_data.wavout = self.wavout
     return tts_data