Beispiel #1
0
	def _loadTTS(self, tts: str, user: User = None) -> TTSEnum:
		try:
			tts = TTSEnum(tts)
		except:
			tts = TTSEnum.SNIPS

		if tts == TTSEnum.PICO:
			self._tts = PicoTTS(user)
		elif tts == TTSEnum.MYCROFT:
			if not Path(Path(self.Commons.rootDir()).parent, 'mimic/voices').is_dir():
				self.logWarning('Trying to use Mycroft as TTS but files not available, falling back to picotts')
				self._tts = PicoTTS(user)
				tts = TTSEnum.PICO
			else:
				from core.voice.model.MycroftTTS import MycroftTTS
				self._tts = MycroftTTS(user)
		elif tts == TTSEnum.AMAZON:
			from core.voice.model.AmazonTTS import AmazonTTS

			self._tts = AmazonTTS(user)
		elif tts == TTSEnum.GOOGLE:
			if not Path(self.Commons.rootDir(), 'credentials/googlecredentials.json').exists():
				self.logWarning('No Google credentials found for Google Wavenet, falling back to pico')
				self._tts = PicoTTS(user)
			else:
				from core.voice.model.GoogleTTS import GoogleTTS

				self._tts = GoogleTTS(user)
		else:
			from core.voice.model.SnipsTTS import SnipsTTS
			self._tts = SnipsTTS(user)

		return tts
Beispiel #2
0
    def _loadTTS(self, tts: str, user: User = None) -> TTSEnum:
        try:
            tts = TTSEnum(tts)
        except:
            tts = TTSEnum.SNIPS

        if tts == TTSEnum.SNIPS:
            from core.voice.model.SnipsTTS import SnipsTTS
            self._tts = SnipsTTS(user)
        elif tts == TTSEnum.PICO:
            self._tts = PicoTTS(user)
        elif tts == TTSEnum.MYCROFT:
            if not Path(Path(commons.rootDir()).parent,
                        'mimic/voices').is_dir():
                self._logger.warning(
                    '[{}] Trying to use Mycroft as TTS but files not available, falling back to picotts'
                    .format(self.NAME))
                self._tts = PicoTTS(user)
                tts = TTSEnum.PICO
            else:
                from core.voice.model.MycroftTTS import MycroftTTS
                self._tts = MycroftTTS(user)
        elif tts == TTSEnum.AMAZON:
            from core.voice.model.AmazonTTS import AmazonTTS
            self._tts = AmazonTTS(user)
        elif tts == TTSEnum.GOOGLE:
            from core.voice.model.GoogleTTS import GoogleTTS
            self._tts = GoogleTTS(user)
        else:
            from core.voice.model.SnipsTTS import SnipsTTS
            self._tts = SnipsTTS(user)

        return tts
Beispiel #3
0
	def onStart(self):
		super().onStart()

		tts = self._loadTTS(self.ConfigManager.getAliceConfigByName('tts').lower())

		if (self.ConfigManager.getAliceConfigByName('stayCompletlyOffline') or self.ConfigManager.getAliceConfigByName('keepTTSOffline')) and self._tts.online:
			self._tts = PicoTTS()
			self.logInfo('Started "Pico" TTS')
		else:
			self.logInfo(f'Started "{tts.value}" TTS')

		self._tts.onStart()
Beispiel #4
0
    def onStart(self):
        super().onStart()

        tts = self._loadTTS(
            self.ConfigManager.getAliceConfigByName('tts').lower())

        if (self.ConfigManager.getAliceConfigByName('stayCompletlyOffline')
                or self.ConfigManager.getAliceConfigByName('keepTTSOffline')
            ) and self._tts.online:
            self._tts = PicoTTS()
            self._logger.info('[{}] Started "Pico" TTS'.format(self.name))
        else:
            self._logger.info('[{}] Started "{}" TTS'.format(
                self.name, tts.value))

        self._tts.onStart()
Beispiel #5
0
	def onInternetLost(self):
		if self._tts.online:
			self._fallback = PicoTTS()
Beispiel #6
0
class TTSManager(Manager):

	def __init__(self):
		super().__init__()

		self._fallback = None
		self._tts = None
		self._cacheRoot = Path(self.Commons.rootDir(), 'var/cache')


	def onStart(self):
		super().onStart()

		tts = self._loadTTS(self.ConfigManager.getAliceConfigByName('tts').lower())

		if (self.ConfigManager.getAliceConfigByName('stayCompletlyOffline') or self.ConfigManager.getAliceConfigByName('keepTTSOffline')) and self._tts.online:
			self._tts = PicoTTS()
			self.logInfo('Started "Pico" TTS')
		else:
			self.logInfo(f'Started "{tts.value}" TTS')

		self._tts.onStart()


	def _loadTTS(self, tts: str, user: User = None) -> TTSEnum:
		try:
			tts = TTSEnum(tts)
		except:
			tts = TTSEnum.SNIPS

		if tts == TTSEnum.PICO:
			self._tts = PicoTTS(user)
		elif tts == TTSEnum.MYCROFT:
			if not Path(Path(self.Commons.rootDir()).parent, 'mimic/voices').is_dir():
				self.logWarning('Trying to use Mycroft as TTS but files not available, falling back to picotts')
				self._tts = PicoTTS(user)
				tts = TTSEnum.PICO
			else:
				from core.voice.model.MycroftTTS import MycroftTTS
				self._tts = MycroftTTS(user)
		elif tts == TTSEnum.AMAZON:
			from core.voice.model.AmazonTTS import AmazonTTS

			self._tts = AmazonTTS(user)
		elif tts == TTSEnum.GOOGLE:
			if not Path(self.Commons.rootDir(), 'credentials/googlecredentials.json').exists():
				self.logWarning('No Google credentials found for Google Wavenet, falling back to pico')
				self._tts = PicoTTS(user)
			else:
				from core.voice.model.GoogleTTS import GoogleTTS

				self._tts = GoogleTTS(user)
		else:
			from core.voice.model.SnipsTTS import SnipsTTS
			self._tts = SnipsTTS(user)

		return tts


	@property
	def tts(self) -> TTS:
		return self._tts


	@property
	def cacheRoot(self) -> Path:
		return self._cacheRoot


	def onInternetLost(self):
		if self._tts.online:
			self._fallback = PicoTTS()


	def onInternetConnected(self):
		self._fallback = None


	def onSay(self, session: DialogSession):
		if self._fallback:
			self._fallback.onSay(session)
			return

		if session and session.user != constants.UNKNOWN_USER:
			user: User = self.UserManager.getUser(session.user)
			if user and user.tts:
				self._loadTTS(user.tts, user)
				self._tts.onStart()

		self._tts.onSay(session)
Beispiel #7
0
class TTSManager(Manager):
    NAME = 'TTSManager'

    CACHE_ROOT = Path(commons.rootDir(), 'var/cache')

    def __init__(self):
        super().__init__(self.NAME)

        self._fallback = None
        self._tts = None

    def onStart(self):
        super().onStart()

        tts = self._loadTTS(
            self.ConfigManager.getAliceConfigByName('tts').lower())

        if (self.ConfigManager.getAliceConfigByName('stayCompletlyOffline')
                or self.ConfigManager.getAliceConfigByName('keepTTSOffline')
            ) and self._tts.online:
            self._tts = PicoTTS()
            self._logger.info('[{}] Started "Pico" TTS'.format(self.name))
        else:
            self._logger.info('[{}] Started "{}" TTS'.format(
                self.name, tts.value))

        self._tts.onStart()

    def _loadTTS(self, tts: str, user: User = None) -> TTSEnum:
        try:
            tts = TTSEnum(tts)
        except:
            tts = TTSEnum.SNIPS

        if tts == TTSEnum.SNIPS:
            from core.voice.model.SnipsTTS import SnipsTTS
            self._tts = SnipsTTS(user)
        elif tts == TTSEnum.PICO:
            self._tts = PicoTTS(user)
        elif tts == TTSEnum.MYCROFT:
            if not Path(Path(commons.rootDir()).parent,
                        'mimic/voices').is_dir():
                self._logger.warning(
                    '[{}] Trying to use Mycroft as TTS but files not available, falling back to picotts'
                    .format(self.NAME))
                self._tts = PicoTTS(user)
                tts = TTSEnum.PICO
            else:
                from core.voice.model.MycroftTTS import MycroftTTS
                self._tts = MycroftTTS(user)
        elif tts == TTSEnum.AMAZON:
            from core.voice.model.AmazonTTS import AmazonTTS
            self._tts = AmazonTTS(user)
        elif tts == TTSEnum.GOOGLE:
            from core.voice.model.GoogleTTS import GoogleTTS
            self._tts = GoogleTTS(user)
        else:
            from core.voice.model.SnipsTTS import SnipsTTS
            self._tts = SnipsTTS(user)

        return tts

    @property
    def tts(self) -> TTS:
        return self._tts

    def onInternetLost(self, *args):
        if self._tts.online:
            self._fallback = PicoTTS()

    def onInternetConnected(self, *args):
        self._fallback = None

    def onSay(self, session: DialogSession):
        if self._fallback:
            self._fallback.onSay(session)
        else:
            if session.user != constants.UNKNOWN_USER:
                user: User = self.UserManager.getUser(session.user)
                if user and user.tts:
                    self._loadTTS(user.tts, user)
                    self._tts.onStart()

            self._tts.onSay(session)