From fd27706a4804014f867917912b4f39969fa98f0e Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 26 Jan 2019 22:35:26 +0100 Subject: [PATCH 1/2] Implement 'stop' in client & briefly start interrupt for server --- hugvey/client.py | 11 +++++++++-- hugvey/story.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) 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'] From 602633373e9f83df225aec881e8522071a899c60 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Mon, 28 Jan 2019 17:26:48 +0100 Subject: [PATCH 2/2] Test version --- hugvey/story.py | 6 ++++-- hugvey/voice/player.py | 1 + local | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index 48402bd..04398ac 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -1,6 +1,7 @@ import json import time import logging +import re import asyncio @@ -83,7 +84,7 @@ class Condition(object): if not story.lastMsgFinishTime: return False - return now - story.lastMsgFinishTime >= self.vars['seconds'] + return now - story.lastMsgFinishTime >= float(self.vars['seconds']) def _hasMetReplyContains(self, story): if not story.currentMessage.hasReply(): @@ -93,13 +94,14 @@ class Condition(object): if 'regexCompiled' not in self.vars: # Compile once, as we probably run it more than once self.vars['regexCompiled'] = re.compile(self.vars['regex']) - result = re.match(self.vars['regexCompiled']) + result = re.match(self.vars['regexCompiled'], story.currentMessage.getReply()) if result is None: return False results = result.groupdict() for captureGroup in results: story.variables[captureGroup] = results[captureGroup] logger.critical("Regex not implemented yet") +# return True return False if 'contains' in self.vars: diff --git a/hugvey/voice/player.py b/hugvey/voice/player.py index e10cab3..83b530a 100644 --- a/hugvey/voice/player.py +++ b/hugvey/voice/player.py @@ -33,6 +33,7 @@ class Player: def get_output_idx(self): output_device_idx = None + output_device_idx = 14 devices_count = self.p.get_device_count() for i in range(devices_count): dev = self.p.get_device_info_by_index(i) diff --git a/local b/local index 71d7b7e..e799809 160000 --- a/local +++ b/local @@ -1 +1 @@ -Subproject commit 71d7b7e1d6a4f4cb1503b845ebb44c4357d42180 +Subproject commit e799809a59522d0f68f99f668a9ddf0f5f629912