17 from threading
import Lock
33 mimic_fallback_obj =
None 40 Force Mycroft to start listening (as if 'Hey Mycroft' was spoken) 47 Handle "speak" message 49 config = Configuration.get()
50 Configuration.init(bus)
51 global _last_stop_signal
54 if event.context
and 'ident' in event.context:
55 ident = event.context[
'ident']
63 utterance = event.data[
'utterance']
64 if event.data.get(
'expect_response',
False):
67 bus.once(
'recognizer_loop:audio_output_end', _start_listener)
77 if (config.get(
'enclosure', {}).
get(
'platform') !=
"picroft" and 78 len(re.findall(
'<[^>]*>', utterance)) == 0):
83 utterance = re.sub(
r'\b([A-za-z][\.])(\s+)',
r'\g<1>', utterance)
84 chunks = re.split(
r'(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\;|\?)\s',
88 if (_last_stop_signal > start
or 95 except KeyboardInterrupt:
98 LOG.error(
'Error in mute_and_speak', exc_info=
True)
103 report_timing(ident,
'speech', stopwatch, {
'utterance': utterance,
104 'tts': tts.__class__.__name__})
109 Mute mic and start speaking the utterance using selected tts backend. 112 utterance: The sentence to be spoken 113 ident: Ident tying the utterance to the source query 118 if tts_hash != hash(str(config.get(
'tts',
''))):
124 tts = TTSFactory.create()
126 tts_hash = hash(str(config.get(
'tts',
'')))
128 LOG.info(
"Speak: " + utterance)
130 tts.execute(utterance, ident)
131 except RemoteTTSTimeoutException
as e:
134 except Exception
as e:
135 LOG.error(
'TTS execution failed ({})'.format(repr(e)))
139 global mimic_fallback_obj
141 config = Configuration.get()
142 tts_config = config.get(
'tts', {}).
get(
"mimic", {})
143 lang = config.get(
"lang",
"en-us")
144 if not mimic_fallback_obj:
145 mimic_fallback_obj =
Mimic(lang, tts_config)
146 tts = mimic_fallback_obj
147 LOG.debug(
"Mimic fallback, utterance : " + str(utterance))
149 tts.execute(utterance, ident)
156 global _last_stop_signal
158 _last_stop_signal = time.time()
160 bus.emit(
Message(
"mycroft.stop.handled", {
"by":
"TTS"}))
164 """ Start speech related handlers. 167 messagebus: Connection to the Mycroft messagebus 176 Configuration.init(bus)
177 config = Configuration.get()
178 bus.on(
'mycroft.stop', handle_stop)
179 bus.on(
'mycroft.audio.speech.stop', handle_stop)
180 bus.on(
'speak', handle_speak)
181 bus.on(
'mycroft.mic.listen', _start_listener)
183 tts = TTSFactory.create()
185 tts_hash = config.get(
'tts')
192 if mimic_fallback_obj:
193 mimic_fallback_obj.playback.stop()
194 mimic_fallback_obj.playback.join()
def report_timing(ident, system, timing, additional_data=None)
def check_for_signal(signal_name, sec_lifetime=0)
def mimic_fallback_tts(utterance, ident)
def create_signal(signal_name)
def mute_and_speak(utterance, ident)
def get(phrase, lang=None, context=None)
def _start_listener(message)