Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/stop speaking #1167

Merged
merged 2 commits into from Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions mycroft/audio/__init__.py
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions mycroft/audio/speech.py
Expand Up @@ -19,7 +19,7 @@

from mycroft.configuration import ConfigurationManager
from mycroft.tts import TTSFactory
from mycroft.util import create_signal, stop_speaking, check_for_signal
from mycroft.util import create_signal, check_for_signal
from mycroft.util.log import LOG

ws = None
Expand Down Expand Up @@ -111,9 +111,10 @@ def handle_stop(event):
handle stop message
"""
global _last_stop_signal
_last_stop_signal = time.time()
tts.playback.clear_queue()
tts.playback.clear_visimes()
if check_for_signal("isSpeaking", -1):
_last_stop_signal = time.time()
tts.playback.clear_queue()
tts.playback.clear_visimes()


def init(websocket):
Expand Down
91 changes: 59 additions & 32 deletions mycroft/messagebus/send.py
Expand Up @@ -19,38 +19,65 @@
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()


# 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()

send(messageToSend, dataToSend)


def send(messageToSend, dataToSend=None):
"""
Send a single message over the websocket.

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()