diff --git a/hugvey/client.py b/hugvey/client.py index 8ba7f05..3046bcb 100644 --- a/hugvey/client.py +++ b/hugvey/client.py @@ -121,6 +121,7 @@ class CommandHandler(object): self.publish_address = publish_address self.playPopen = None self.file_address = file_address + self.playingMsgId = None # self.showMyself() # queue message for connection request def handle(self, cmd): @@ -135,6 +136,8 @@ class CommandHandler(object): self.showMyself() if cmd['action'] == 'play': self.cmdPlay(cmd) + if cmd['action'] == 'stop': + self.cmdPlay(cmd, cmd['id']) def cmdPlay(self, cmd): @@ -142,6 +145,7 @@ class CommandHandler(object): pitch = cmd['pitch'] if 'pitch' in cmd else 50 file = cmd['file'] if 'file' in cmd else None text = cmd['msg'] if 'msg' in cmd else None + self.playingMsgId = msgId if file is None and text is None: logger.critical("No file nor text given: {}".format(cmd)) @@ -162,19 +166,22 @@ class CommandHandler(object): logger.warn("Had returncode on play: {}".format(returnCode)) else: logger.debug("Finished playback. Return code: {}".format(returnCode)) - + + self.playingMsgId = None self.sendMessage({ 'event': 'playbackFinish', 'msgId': msgId }) def cmdStop(self, msgId): - if self.playPopen: + if self.playPopen and self.playingMsgId == msgId: logger.info("Interrupting playback") try: self.playPopen.terminate() except Exception as e: logger.critical("Could not stop playback: {}".format(e)) + else: + logger.warn("Interrupt ignored") def showMyself(self): """Publish about this hugvey to central command diff --git a/hugvey/story.py b/hugvey/story.py index 68a81e6..48402bd 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -351,7 +351,7 @@ class Story(object): if e['event'] == "exit": self.stop() if e['event'] == 'connect': - # a client connected. Shold only happen in the beginning or in case of error + # a client connected. Should only happen in the beginning or in case of error # that is, until we have a 'reset' or 'start' event. # reinitiate current message self.setCurrentMessage(self.currentMessage) @@ -366,8 +366,20 @@ class Story(object): return if e['event'] == 'speech': +# message is still playing: + if self.currentMessage and not self.lastMsgFinishTime: + #interrupt: +# FINISH THIS!!! +# self.hugvey.sendCommand({ +# 'action': 'stop', +# 'id': self.currentMessage.id, +# }) +# .... + pass + # log if somebody starts speaking # TODO: use pausing timer + # TODO: implement interrupt if self.lastSpeechStartTime is None or self.lastSpeechStartTime < self.lastMsgTime: self.lastSpeechStartTime = e['time']