def synthesize_multiple(self, text_file, ofp=None, quit_after=None, backwards=False, zero_length=False): if ofp is None: handler, output_file_path = gf.tmp_file(suffix=".wav") else: handler = None output_file_path = ofp try: rconf = RuntimeConfiguration() rconf[RuntimeConfiguration.TTS] = u"festival" rconf[RuntimeConfiguration.TTS_PATH] = u"text2wave" tts_engine = FESTIVALWrapper(rconf=rconf) anchors, total_time, num_chars = tts_engine.synthesize_multiple( text_file, output_file_path, quit_after, backwards ) gf.delete_file(handler, output_file_path) if zero_length: self.assertEqual(total_time, 0.0) else: self.assertGreater(total_time, 0.0) except (OSError, TypeError, UnicodeDecodeError, ValueError) as exc: gf.delete_file(handler, output_file_path) raise exc
def synthesize_multiple(self, text_file, ofp=None, quit_after=None, backwards=False, zero_length=False): if ofp is None: handler, output_file_path = gf.tmp_file(suffix=".wav") else: handler = None output_file_path = ofp try: rconf = RuntimeConfiguration() rconf[RuntimeConfiguration.TTS] = u"festival" rconf[RuntimeConfiguration.TTS_PATH] = u"text2wave" tts_engine = FESTIVALWrapper(rconf=rconf) anchors, total_time, num_chars = tts_engine.synthesize_multiple( text_file, output_file_path, quit_after, backwards) gf.delete_file(handler, output_file_path) if zero_length: self.assertEqual(total_time, 0.0) else: self.assertGreater(total_time, 0.0) except (OSError, TypeError, UnicodeDecodeError, ValueError) as exc: gf.delete_file(handler, output_file_path) raise exc
def synthesize_single(self, text, language, ofp=None, zero_length=False): if ofp is None: handler, output_file_path = gf.tmp_file(suffix=".wav") else: handler = None output_file_path = ofp try: rconf = RuntimeConfiguration() rconf[RuntimeConfiguration.TTS] = u"festival" rconf[RuntimeConfiguration.TTS_PATH] = u"text2wave" tts_engine = FESTIVALWrapper(rconf=rconf) result = tts_engine.synthesize_single(text, language, output_file_path) gf.delete_file(handler, output_file_path) if zero_length: self.assertEqual(result, 0) else: self.assertGreater(result, 0) except (OSError, TypeError, UnicodeDecodeError, ValueError) as exc: gf.delete_file(handler, output_file_path) raise exc
def _select_tts_engine(self): """ Select the TTS engine to be used by looking at the rconf object. """ self.log(u"Selecting TTS engine...") if self.rconf[RuntimeConfiguration.TTS] == self.CUSTOM: self.log(u"TTS engine: custom") tts_path = self.rconf[RuntimeConfiguration.TTS_PATH] if not gf.file_can_be_read(tts_path): self.log_exc(u"Cannot read tts_path", None, True, OSError) try: import imp self.log([ u"Loading CustomTTSWrapper module from '%s'...", tts_path ]) imp.load_source("CustomTTSWrapperModule", tts_path) self.log([ u"Loading CustomTTSWrapper module from '%s'... done", tts_path ]) self.log(u"Importing CustomTTSWrapper...") from CustomTTSWrapperModule import CustomTTSWrapper self.log(u"Importing CustomTTSWrapper... done") self.log(u"Creating CustomTTSWrapper instance...") self.tts_engine = CustomTTSWrapper(rconf=self.rconf, logger=self.logger) self.log(u"Creating CustomTTSWrapper instance... done") except Exception as exc: self.log_exc(u"Unable to load custom TTS wrapper", exc, True, OSError) elif self.rconf[RuntimeConfiguration.TTS] == self.FESTIVAL: self.log(u"TTS engine: Festival") self.tts_engine = FESTIVALWrapper(rconf=self.rconf, logger=self.logger) elif self.rconf[RuntimeConfiguration.TTS] == self.NUANCETTSAPI: try: import requests except ImportError as exc: self.log_exc( u"Unable to import requests for Nuance TTS API wrapper", exc, True, ImportError) self.log(u"TTS engine: Nuance TTS API") self.tts_engine = NuanceTTSAPIWrapper(rconf=self.rconf, logger=self.logger) else: self.log(u"TTS engine: eSpeak") self.tts_engine = ESPEAKWrapper(rconf=self.rconf, logger=self.logger) self.log(u"Selecting TTS engine... done")