From 89e9c2ff7739dbd202d7231e77d24f211a39c2bc Mon Sep 17 00:00:00 2001 From: Jonathan D'Orleans Date: Thu, 8 Sep 2016 11:31:40 -0400 Subject: [PATCH] Issues 351 - Moving TTS Factory to tts __init__.py --- mycroft/client/speech/main.py | 4 +-- mycroft/client/text/cli.py | 4 +-- mycroft/tts/__init__.py | 50 ++++++++++++++++++++++++++ mycroft/tts/tts_factory.py | 68 ----------------------------------- 4 files changed, 54 insertions(+), 72 deletions(-) delete mode 100644 mycroft/tts/tts_factory.py diff --git a/mycroft/client/speech/main.py b/mycroft/client/speech/main.py index e004cbfc6a..ef566e9f48 100644 --- a/mycroft/client/speech/main.py +++ b/mycroft/client/speech/main.py @@ -26,13 +26,13 @@ from mycroft.client.speech.listener import RecognizerLoop from mycroft.configuration import ConfigurationManager from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.message import Message -from mycroft.tts import tts_factory +from mycroft.tts import TTSFactory from mycroft.util import kill from mycroft.util.log import getLogger logger = getLogger("SpeechClient") client = None -tts = tts_factory.create() +tts = TTSFactory.create() mutex = Lock() loop = None diff --git a/mycroft/client/text/cli.py b/mycroft/client/text/cli.py index d292bc81e3..c8549abd85 100644 --- a/mycroft/client/text/cli.py +++ b/mycroft/client/text/cli.py @@ -21,10 +21,10 @@ from threading import Thread, Lock from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.message import Message -from mycroft.tts import tts_factory +from mycroft.tts import TTSFactory from mycroft.util.log import getLogger -tts = tts_factory.create() +tts = TTSFactory.create() client = None mutex = Lock() logger = getLogger("CLIClient") diff --git a/mycroft/tts/__init__.py b/mycroft/tts/__init__.py index 16bdcd44ce..a2724a39ce 100644 --- a/mycroft/tts/__init__.py +++ b/mycroft/tts/__init__.py @@ -16,9 +16,18 @@ # along with Mycroft Core. If not, see . +import logging + import abc from os.path import dirname, exists, isdir +from mycroft.configuration import ConfigurationManager +from mycroft.tts import espeak_tts +from mycroft.tts import fa_tts +from mycroft.tts import google_tts +from mycroft.tts import mary_tts +from mycroft.tts import mimic_tts +from mycroft.tts import spdsay_tts from mycroft.util.log import getLogger __author__ = 'jdorleans' @@ -91,3 +100,44 @@ class TTSValidator(object): @abc.abstractmethod def get_instance(self): pass + + +class TTSFactory(object): + @staticmethod + def create(): + """ + Factory method to create a TTS engine based on configuration. + + The configuration file ``mycroft.conf`` contains a ``tts`` section with + the name of a TTS module to be read by this method. + + "tts": { + "module": + } + """ + + logging.basicConfig() + config = ConfigurationManager.get().get('tts') + name = config.get('module') + lang = config.get(name).get('lang') + voice = config.get(name).get('voice') + + if name == mimic_tts.NAME: + tts = mimic_tts.Mimic(lang, voice) + mimic_tts.MimicValidator().validate(tts) + elif name == google_tts.NAME: + tts = google_tts.GoogleTTS(lang, voice) + google_tts.GoogleTTSValidator().validate(tts) + elif name == mary_tts.NAME: + tts = mary_tts.MaryTTS(lang, voice, config[name + '.url']) + mary_tts.MaryTTSValidator().validate(tts) + elif name == fa_tts.NAME: + tts = fa_tts.FATTS(lang, voice, config[name + '.url']) + fa_tts.FATTSValidator().validate(tts) + elif name == espeak_tts.NAME: + tts = espeak_tts.ESpeak(lang, voice) + espeak_tts.ESpeakValidator().validate(tts) + else: + tts = spdsay_tts.SpdSay(lang, voice) + spdsay_tts.SpdSayValidator().validate(tts) + return tts diff --git a/mycroft/tts/tts_factory.py b/mycroft/tts/tts_factory.py deleted file mode 100644 index 555cd4d921..0000000000 --- a/mycroft/tts/tts_factory.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2016 Mycroft AI, Inc. -# -# This file is part of Mycroft Core. -# -# Mycroft Core is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Mycroft Core is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Mycroft Core. If not, see . - - -import logging - -from mycroft.configuration import ConfigurationManager -from mycroft.tts import espeak_tts -from mycroft.tts import fa_tts -from mycroft.tts import google_tts -from mycroft.tts import mary_tts -from mycroft.tts import mimic_tts -from mycroft.tts import spdsay_tts - -__author__ = 'jdorleans' - - -def create(): - """ - Factory method to create a TTS engine based on configuration. - - The configuration file ``defaults.ini`` contains a ``tts`` section with - the name of a TTS module to be read by this method. - - [tts] - - module = - """ - - logging.basicConfig() - config = ConfigurationManager.get().get('tts') - name = config.get('module') - lang = config.get(name + '.lang', None) - voice = config.get(name + '.voice') - - if name == mimic_tts.NAME: - tts = mimic_tts.Mimic(lang, voice) - mimic_tts.MimicValidator().validate(tts) - elif name == google_tts.NAME: - tts = google_tts.GoogleTTS(lang, voice) - google_tts.GoogleTTSValidator().validate(tts) - elif name == mary_tts.NAME: - tts = mary_tts.MaryTTS(lang, voice, config[name + '.url']) - mary_tts.MaryTTSValidator().validate(tts) - elif name == fa_tts.NAME: - tts = fa_tts.FATTS(lang, voice, config[name + '.url']) - fa_tts.FATTSValidator().validate(tts) - elif name == espeak_tts.NAME: - tts = espeak_tts.ESpeak(lang, voice) - espeak_tts.ESpeakValidator().validate(tts) - else: - tts = spdsay_tts.SpdSay(lang, voice) - spdsay_tts.SpdSayValidator().validate(tts) - return tts