diff --git a/channel_rewards/implemented/ChannelReward_Hydration.py b/channel_rewards/implemented/ChannelReward_Hydration.py index 409620d..c7d20ab 100644 --- a/channel_rewards/implemented/ChannelReward_Hydration.py +++ b/channel_rewards/implemented/ChannelReward_Hydration.py @@ -6,6 +6,8 @@ from json import loads from urllib.parse import urlencode import requests +import threading + class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): """ this is the hydration reward. @@ -16,12 +18,25 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): super().__init__(ChannelReward_Hydration.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) self.help = ["This is a hydration channel point reward."] self.isChannelRewardEnabled = True + self.threads = [] def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): #print("sending:",user, 16, "!lights hydration") - self.dothething(user, 16, "!lights hydration", "") - self.send_TTS(user, rewardPrompt) + try: + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.send_TTS, args=(user, rewardPrompt)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + return None def dothething(self, username, light_group, command, rest): diff --git a/channel_rewards/implemented/ChannelReward_RubiksCube.py b/channel_rewards/implemented/ChannelReward_RubiksCube.py index 11b397e..b7ca673 100644 --- a/channel_rewards/implemented/ChannelReward_RubiksCube.py +++ b/channel_rewards/implemented/ChannelReward_RubiksCube.py @@ -40,5 +40,21 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): # todo handle failed requests pass + def send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + def get_help(self): return self.help \ No newline at end of file diff --git a/commands/implemented/Command_lights_v2.py b/commands/implemented/Command_lights_v2.py index 1aff57a..78bb382 100644 --- a/commands/implemented/Command_lights_v2.py +++ b/commands/implemented/Command_lights_v2.py @@ -37,7 +37,7 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta): praxis_logger_obj.log(user_) praxis_logger_obj.log(user) returnString = self.dothething(user, 16, command, rest) - isTwitch = True + isTwitch = True if isTwitch == False: returnString = self.dothething(user, 16, command, rest) diff --git a/standalone_lights.py b/standalone_lights.py index f237f8f..dc47ab6 100644 --- a/standalone_lights.py +++ b/standalone_lights.py @@ -106,7 +106,7 @@ class Lights_Module(): def hydration(self): self.bridge_.run_scene("Downstairs", "hydration") - sleep(20) + sleep(4) self.bridge_.run_scene("Downstairs", "Stream") def raveMode(self): diff --git a/standalone_tts_core.py b/standalone_tts_core.py index 19e0210..7a051bf 100644 --- a/standalone_tts_core.py +++ b/standalone_tts_core.py @@ -21,21 +21,22 @@ def init(): def send_text(tts_sender, tts_text): - #Play Audio File + #Play Text params = urlencode({'tts_sender': tts_sender, 'tts_text': tts_text}) - url = "http://localhost:93986/api/v1/tts/speech?%s" % params + url = "http://192.168.191.208:40085/api/v1/tts/speech?%s" % params resp = requests.get(url) if resp.status_code == 200: print("Got the following message: %s" % resp.text) data = loads(resp.text) - msg = data['message'] - if msg is not None: - pass - else: + #msg = data['message'] + #if msg is not None: + #pass + #else: # todo handle failed requests - pass + #pass + #return None return flask.make_response('', 200) @api.route('/api/v1/tts/send_text', methods=['GET']) @@ -48,5 +49,6 @@ def tts_send_text(): return send_text(request.args['tts_sender'], request.args['tts_text']) if __name__ == '__main__': - init() + #send_text("","Blah Blah Blah") + #init() api.run(host='0.0.0.0', port=60809) \ No newline at end of file diff --git a/standalone_tts_speaker.py b/standalone_tts_speaker.py index 9907f1c..c7c1103 100644 --- a/standalone_tts_speaker.py +++ b/standalone_tts_speaker.py @@ -35,18 +35,20 @@ def isTTS_URL_Check(message): if not is_ttsEnabled: isNotBlocked = False - return isNotBlocked + return not isNotBlocked def try_TTS(tts_sender, tts_text): text_to_say: str = "%s says, %s" % (tts_sender, tts_text) - if tts_sender is None: + #tts.tts(str(text_to_say)) + #tts.tts(str(tts_text)) + if tts_sender == "": text_to_say = tts_text if isTTS_URL_Check(tts_text): if not utility.contains_slur(tts_sender): if not utility.contains_slur(text_to_say): - tts.tts(text_to_say) + tts.tts(str(text_to_say)) return flask.make_response('', 200) @@ -54,11 +56,13 @@ def try_TTS(tts_sender, tts_text): def tts_speech(): if 'tts_sender' not in request.args: tts_sender = "" + else: + tts_sender = request.args['tts_sender'] if 'tts_text' not in request.args: return flask.make_response('{\"text\":"Argument \'tts_text\' not in request"}', 400) - return try_TTS(request.args['tts_text']) + return try_TTS(tts_sender, request.args['tts_text']) if __name__ == '__main__': - init() - api.run(host='0.0.0.0', port=93986) \ No newline at end of file + #init() + api.run(host='0.0.0.0', port=40085) \ No newline at end of file