Fix sending message in stop_speaking()

====  Tech Notes ====
Previous approach did not work as websocket client was not running, this
uses the standalone send functionality recently added to send a single
message.
pull/1150/head^2
Åke Forslund 2017-10-17 13:45:39 +02:00 committed by Steve Penrod
parent e5f2e3d5cd
commit 7814e207d3
2 changed files with 59 additions and 37 deletions

View File

@ -39,17 +39,12 @@ def wait_while_speaking():
time.sleep(0.1)
def stop_speaking(ws=None):
from mycroft.messagebus.client.ws import WebsocketClient
from mycroft.messagebus.message import Message
if ws is None:
ws = WebsocketClient()
def stop_speaking():
# TODO: Less hacky approach to this once Audio Manager is implemented
# Skills should only be able to stop speech they've initiated
from mycroft.messagebus.send import send
create_signal('stoppingTTS')
ws.emit(Message('mycroft.audio.speech.stop'))
send('mycroft.audio.speech.stop')
# Block until stopped
while check_for_signal("isSpeaking", -1):

View File

@ -19,38 +19,65 @@ from mycroft.messagebus.message import Message
from mycroft.configuration import ConfigurationManager
from websocket import create_connection
# Parse the command line
if len(sys.argv) == 2:
messageToSend = sys.argv[1]
dataToSend = {}
elif len(sys.argv) == 3:
messageToSend = sys.argv[1]
try:
dataToSend = json.loads(sys.argv[2])
except BaseException:
print "Second argument must be a JSON string"
def main():
"""
Main function, will run if executed from command line.
Sends parameters from commandline.
Param 1: message string
Param 2: data (json string)
"""
# Parse the command line
if len(sys.argv) == 2:
messageToSend = sys.argv[1]
dataToSend = {}
elif len(sys.argv) == 3:
messageToSend = sys.argv[1]
try:
dataToSend = json.loads(sys.argv[2])
except BaseException:
print "Second argument must be a JSON string"
print "Ex: python -m mycroft.messagebus.send speak " \
"'{\"utterance\" : \"hello\"}'"
exit()
else:
print "Command line interface to the mycroft-core messagebus."
print "Usage: python -m mycroft.messagebus.send message"
print " python -m mycroft.messagebus.send message JSON-string\n"
print "Examples: python -m mycroft.messagebus.send mycroft.wifi.start"
print "Ex: python -m mycroft.messagebus.send speak " \
"'{\"utterance\" : \"hello\"}'"
exit()
else:
print "Command line interface to the mycroft-core messagebus."
print "Usage: python -m mycroft.messagebus.send message"
print " python -m mycroft.messagebus.send message JSON-string\n"
print "Examples: python -m mycroft.messagebus.send mycroft.wifi.start"
print "Ex: python -m mycroft.messagebus.send speak " \
"'{\"utterance\" : \"hello\"}'"
exit()
send(messageToSend, dataToSend)
# Calculate the standard Mycroft messagebus websocket address
config = ConfigurationManager.get().get("websocket")
url = WebsocketClient.build_url(config.get("host"),
config.get("port"),
config.get("route"),
config.get("ssl"))
def send(messageToSend, dataToSend=None):
"""
Send a single message over the websocket.
# Send the provided message/data
ws = create_connection(url)
packet = Message(messageToSend, dataToSend).serialize()
ws.send(packet)
ws.close()
Args:
messageToSend (str): Message to send
dataToSend (dict): data structure to go along with the
message, defaults to empty dict.
"""
dataToSend = dataToSend or {}
# Calculate the standard Mycroft messagebus websocket address
config = ConfigurationManager.get().get("websocket")
url = WebsocketClient.build_url(config.get("host"),
config.get("port"),
config.get("route"),
config.get("ssl"))
# Send the provided message/data
ws = create_connection(url)
packet = Message(messageToSend, dataToSend).serialize()
ws.send(packet)
ws.close()
if __name__ == '__main__':
main()