Merge branch 'master' of https://gitlab.com/hugvey/hugvey
This commit is contained in:
commit
fe2160e3cb
4 changed files with 28 additions and 6 deletions
|
@ -125,6 +125,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):
|
||||||
|
@ -139,6 +140,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):
|
||||||
|
@ -146,6 +149,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))
|
||||||
|
@ -166,19 +170,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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ class Condition(object):
|
||||||
if not story.lastMsgFinishTime:
|
if not story.lastMsgFinishTime:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return now - story.lastMsgFinishTime >= self.vars['seconds']
|
return now - story.lastMsgFinishTime >= float(self.vars['seconds'])
|
||||||
|
|
||||||
def _hasMetReplyContains(self, story):
|
def _hasMetReplyContains(self, story):
|
||||||
if not story.currentMessage.hasReply():
|
if not story.currentMessage.hasReply():
|
||||||
|
@ -93,13 +94,14 @@ class Condition(object):
|
||||||
if 'regexCompiled' not in self.vars:
|
if 'regexCompiled' not in self.vars:
|
||||||
# Compile once, as we probably run it more than once
|
# Compile once, as we probably run it more than once
|
||||||
self.vars['regexCompiled'] = re.compile(self.vars['regex'])
|
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:
|
if result is None:
|
||||||
return False
|
return False
|
||||||
results = result.groupdict()
|
results = result.groupdict()
|
||||||
for captureGroup in results:
|
for captureGroup in results:
|
||||||
story.variables[captureGroup] = results[captureGroup]
|
story.variables[captureGroup] = results[captureGroup]
|
||||||
logger.critical("Regex not implemented yet")
|
logger.critical("Regex not implemented yet")
|
||||||
|
# return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if 'contains' in self.vars:
|
if 'contains' in self.vars:
|
||||||
|
@ -351,7 +353,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 +368,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']
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Player:
|
||||||
|
|
||||||
def get_output_idx(self):
|
def get_output_idx(self):
|
||||||
output_device_idx = None
|
output_device_idx = None
|
||||||
|
output_device_idx = 14
|
||||||
devices_count = self.p.get_device_count()
|
devices_count = self.p.get_device_count()
|
||||||
for i in range(devices_count):
|
for i in range(devices_count):
|
||||||
dev = self.p.get_device_info_by_index(i)
|
dev = self.p.get_device_info_by_index(i)
|
||||||
|
|
2
local
2
local
|
@ -1 +1 @@
|
||||||
Subproject commit 71d7b7e1d6a4f4cb1503b845ebb44c4357d42180
|
Subproject commit e799809a59522d0f68f99f668a9ddf0f5f629912
|
Loading…
Reference in a new issue