Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Validate the fallback tts
Browse files Browse the repository at this point in the history
  • Loading branch information
forslund committed Nov 14, 2020
1 parent 16a5b99 commit ffe3ef5
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions mycroft/audio/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,31 @@ def mute_and_speak(utterance, ident, listen=False):
LOG.error('TTS execution failed ({})'.format(repr(e)))


def mimic_fallback_tts(utterance, ident, listen):
def _get_mimic_fallback():
"""Lazily initializes the fallback TTS if needed."""
global mimic_fallback_obj
# fallback if connection is lost
config = Configuration.get()
tts_config = config.get('tts', {}).get("mimic", {})
lang = config.get("lang", "en-us")
if not mimic_fallback_obj:
mimic_fallback_obj = Mimic(lang, tts_config)
mimic_fallback_obj.validator.validate()
tts = mimic_fallback_obj
config = Configuration.get()
tts_config = config.get('tts', {}).get("mimic", {})
lang = config.get("lang", "en-us")
tts = Mimic(lang, tts_config)
tts.validator.validate()
tts.init(bus)
mimic_fallback_obj = tts

return mimic_fallback_obj


def mimic_fallback_tts(utterance, ident, listen):
"""Speak utterance using fallback TTS if connection is lost.
Arguments:
utterance (str): sentence to speak
ident (str): interaction id for metrics
listen (bool): True if interaction should end with mycroft listening
"""
tts = _get_mimic_fallback()
LOG.debug("Mimic fallback, utterance : " + str(utterance))
tts.init(bus)
tts.execute(utterance, ident, listen)


Expand Down

0 comments on commit ffe3ef5

Please sign in to comment.