Implement 'stop' in client & briefly start interrupt for server
This commit is contained in:
parent
f93bcbb457
commit
fd27706a48
2 changed files with 22 additions and 3 deletions
|
@ -121,6 +121,7 @@ class CommandHandler(object):
|
||||||
self.publish_address = publish_address
|
self.publish_address = publish_address
|
||||||
self.playPopen = None
|
self.playPopen = None
|
||||||
self.file_address = file_address
|
self.file_address = file_address
|
||||||
|
self.playingMsgId = None
|
||||||
# self.showMyself() # queue message for connection request
|
# self.showMyself() # queue message for connection request
|
||||||
|
|
||||||
def handle(self, cmd):
|
def handle(self, cmd):
|
||||||
|
@ -135,6 +136,8 @@ class CommandHandler(object):
|
||||||
self.showMyself()
|
self.showMyself()
|
||||||
if cmd['action'] == 'play':
|
if cmd['action'] == 'play':
|
||||||
self.cmdPlay(cmd)
|
self.cmdPlay(cmd)
|
||||||
|
if cmd['action'] == 'stop':
|
||||||
|
self.cmdPlay(cmd, cmd['id'])
|
||||||
|
|
||||||
|
|
||||||
def cmdPlay(self, cmd):
|
def cmdPlay(self, cmd):
|
||||||
|
@ -142,6 +145,7 @@ class CommandHandler(object):
|
||||||
pitch = cmd['pitch'] if 'pitch' in cmd else 50
|
pitch = cmd['pitch'] if 'pitch' in cmd else 50
|
||||||
file = cmd['file'] if 'file' in cmd else None
|
file = cmd['file'] if 'file' in cmd else None
|
||||||
text = cmd['msg'] if 'msg' in cmd else None
|
text = cmd['msg'] if 'msg' in cmd else None
|
||||||
|
self.playingMsgId = msgId
|
||||||
|
|
||||||
if file is None and text is None:
|
if file is None and text is None:
|
||||||
logger.critical("No file nor text given: {}".format(cmd))
|
logger.critical("No file nor text given: {}".format(cmd))
|
||||||
|
@ -162,19 +166,22 @@ class CommandHandler(object):
|
||||||
logger.warn("Had returncode on play: {}".format(returnCode))
|
logger.warn("Had returncode on play: {}".format(returnCode))
|
||||||
else:
|
else:
|
||||||
logger.debug("Finished playback. Return code: {}".format(returnCode))
|
logger.debug("Finished playback. Return code: {}".format(returnCode))
|
||||||
|
|
||||||
|
self.playingMsgId = None
|
||||||
self.sendMessage({
|
self.sendMessage({
|
||||||
'event': 'playbackFinish',
|
'event': 'playbackFinish',
|
||||||
'msgId': msgId
|
'msgId': msgId
|
||||||
})
|
})
|
||||||
|
|
||||||
def cmdStop(self, msgId):
|
def cmdStop(self, msgId):
|
||||||
if self.playPopen:
|
if self.playPopen and self.playingMsgId == msgId:
|
||||||
logger.info("Interrupting playback")
|
logger.info("Interrupting playback")
|
||||||
try:
|
try:
|
||||||
self.playPopen.terminate()
|
self.playPopen.terminate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical("Could not stop playback: {}".format(e))
|
logger.critical("Could not stop playback: {}".format(e))
|
||||||
|
else:
|
||||||
|
logger.warn("Interrupt ignored")
|
||||||
|
|
||||||
def showMyself(self):
|
def showMyself(self):
|
||||||
"""Publish about this hugvey to central command
|
"""Publish about this hugvey to central command
|
||||||
|
|
|
@ -351,7 +351,7 @@ class Story(object):
|
||||||
if e['event'] == "exit":
|
if e['event'] == "exit":
|
||||||
self.stop()
|
self.stop()
|
||||||
if e['event'] == 'connect':
|
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.
|
# that is, until we have a 'reset' or 'start' event.
|
||||||
# reinitiate current message
|
# reinitiate current message
|
||||||
self.setCurrentMessage(self.currentMessage)
|
self.setCurrentMessage(self.currentMessage)
|
||||||
|
@ -366,8 +366,20 @@ class Story(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if e['event'] == 'speech':
|
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
|
# log if somebody starts speaking
|
||||||
# TODO: use pausing timer
|
# TODO: use pausing timer
|
||||||
|
# TODO: implement interrupt
|
||||||
if self.lastSpeechStartTime is None or self.lastSpeechStartTime < self.lastMsgTime:
|
if self.lastSpeechStartTime is None or self.lastSpeechStartTime < self.lastMsgTime:
|
||||||
self.lastSpeechStartTime = e['time']
|
self.lastSpeechStartTime = e['time']
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue