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

Commit 3843f5a

Browse files
Steve Penrodforslund
authored andcommitted
Add "wait" option to MycroftSkill.speak() and speak_dialog() (#1812)
* Add "wait" option to MycroftSkill.speak() and speak_dialog() The new "wait" option will cause the speak function to block until all of the given dialog has been spoken by Mycroft. This means: self.speak("Hello world", wait=True) is now equivalent to: self.speak("Hello world") wait_while_speaking()
1 parent 4a8e0e9 commit 3843f5a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mycroft/skills/core.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,14 +965,16 @@ def register_regex(self, regex_str):
965965
re.compile(regex) # validate regex
966966
self.bus.emit(Message('register_vocab', {'regex': regex}))
967967

968-
def speak(self, utterance, expect_response=False):
968+
def speak(self, utterance, expect_response=False, wait=False):
969969
""" Speak a sentence.
970970
971971
Args:
972972
utterance (str): sentence mycroft should speak
973973
expect_response (bool): set to True if Mycroft should listen
974974
for a response immediately after
975975
speaking the utterance.
976+
wait (bool): set to True to block while the text
977+
is being spoken.
976978
"""
977979
# registers the skill as being active
978980
self.enclosure.register(self.name)
@@ -983,19 +985,25 @@ def speak(self, utterance, expect_response=False):
983985
self.bus.emit(message.reply("speak", data))
984986
else:
985987
self.bus.emit(Message("speak", data))
988+
if wait:
989+
wait_while_speaking()
986990

987-
def speak_dialog(self, key, data=None, expect_response=False):
991+
def speak_dialog(self, key, data=None, expect_response=False, wait=False):
988992
""" Speak a random sentence from a dialog file.
989993
990994
Args:
991-
key (str): dialog file key (filename without extension)
995+
key (str): dialog file key (e.g. "hello" to speak from the file
996+
"locale/en-us/hello.dialog")
992997
data (dict): information used to populate sentence
993998
expect_response (bool): set to True if Mycroft should listen
994999
for a response immediately after
9951000
speaking the utterance.
1001+
wait (bool): set to True to block while the text
1002+
is being spoken.
9961003
"""
9971004
data = data or {}
998-
self.speak(self.dialog_renderer.render(key, data), expect_response)
1005+
self.speak(self.dialog_renderer.render(key, data),
1006+
expect_response, wait)
9991007

10001008
def init_dialog(self, root_directory):
10011009
# If "<skill>/dialog/<lang>" exists, load from there. Otherwise

0 commit comments

Comments
 (0)