This commit is contained in:
Begüm Erciyas 2019-01-28 17:27:43 +01:00
commit fe2160e3cb
4 changed files with 28 additions and 6 deletions

View File

@ -125,6 +125,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):
@ -139,6 +140,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):
@ -146,6 +149,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))
@ -166,19 +170,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

View File

@ -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:
@ -351,7 +353,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 +368,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']

View File

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

2
local

@ -1 +1 @@
Subproject commit 71d7b7e1d6a4f4cb1503b845ebb44c4357d42180
Subproject commit e799809a59522d0f68f99f668a9ddf0f5f629912