Merge pull request 'tts-core-&-speaker' (#36) from tts-core-&-speaker into v2.0
Reviewed-on: #36
This commit is contained in:
commit
834bae4773
11
Dockerfile_standalone_tts_core
Normal file
11
Dockerfile_standalone_tts_core
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3.10.0a7-alpine3.13
|
||||||
|
|
||||||
|
WORKDIR /Praxis
|
||||||
|
|
||||||
|
COPY requirements_sa_command.txt requirements_sa_command.txt
|
||||||
|
RUN apk add --update gcc libc-dev linux-headers && rm -rf /var/cache/apk/*
|
||||||
|
RUN pip3 install -r requirements_sa_command.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD [ "python3", "standalone_tts_core.py"]
|
||||||
@ -6,21 +6,37 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
import threading
|
||||||
|
|
||||||
|
class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
this is the hydration reward.
|
this is the hydration reward.
|
||||||
"""
|
"""
|
||||||
ChannelRewardName = "Hydrate"
|
ChannelRewardName = "Hydrate"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(ChannelReward_Hydration_v2.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints)
|
super().__init__(ChannelReward_Hydration.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints)
|
||||||
self.help = ["This is a hydration channel point reward."]
|
self.help = ["This is a hydration channel point reward."]
|
||||||
self.isChannelRewardEnabled = True
|
self.isChannelRewardEnabled = True
|
||||||
|
self.threads = []
|
||||||
|
|
||||||
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
||||||
|
|
||||||
#print("sending:",user, 16, "!lights hydration")
|
#print("sending:",user, 16, "!lights hydration")
|
||||||
self.dothething(user, 16, "!lights hydration", "")
|
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
|
return None
|
||||||
|
|
||||||
def dothething(self, username, light_group, command, rest):
|
def dothething(self, username, light_group, command, rest):
|
||||||
@ -40,5 +56,21 @@ class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
# todo handle failed requests
|
# todo handle failed requests
|
||||||
pass
|
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):
|
def get_help(self):
|
||||||
return self.help
|
return self.help
|
||||||
77
channel_rewards/implemented/ChannelReward_RubiksCube.py
Normal file
77
channel_rewards/implemented/ChannelReward_RubiksCube.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from channel_rewards.channelRewards_base import AbstractChannelRewards
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
this is the hydration reward.
|
||||||
|
"""
|
||||||
|
ChannelRewardName = "Solve a Rubiks Cube"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ChannelReward_RubiksCube.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints)
|
||||||
|
self.help = ["This is a rubiks cube reward."]
|
||||||
|
self.isChannelRewardEnabled = True
|
||||||
|
self.threads = []
|
||||||
|
|
||||||
|
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
||||||
|
|
||||||
|
#self.dothething(user, 16, "!lights rubikscube", "")
|
||||||
|
|
||||||
|
try:
|
||||||
|
if self.is_ChannelReward_enabled:
|
||||||
|
thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights rubikscube", ""))
|
||||||
|
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):
|
||||||
|
# todo need to url-escape command and rest
|
||||||
|
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||||
|
#standalone_lights
|
||||||
|
url = "http://standalone_lights:42069/api/v1/exec_lights?%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 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
|
||||||
76
channel_rewards/implemented/ChannelReward_twitchBits.py
Normal file
76
channel_rewards/implemented/ChannelReward_twitchBits.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from channel_rewards.channelRewards_base import AbstractChannelRewards
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
this is the hydration reward.
|
||||||
|
"""
|
||||||
|
ChannelRewardName = "TwitchBits"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ChannelReward_TwitchBits.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.twitch_bits)
|
||||||
|
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")
|
||||||
|
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):
|
||||||
|
# todo need to url-escape command and rest
|
||||||
|
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||||
|
#standalone_lights
|
||||||
|
url = "http://standalone_lights:42069/api/v1/exec_lights?%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 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
|
||||||
76
channel_rewards/implemented/ChannelReward_twitchSubs.py
Normal file
76
channel_rewards/implemented/ChannelReward_twitchSubs.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from channel_rewards.channelRewards_base import AbstractChannelRewards
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
this is the TwitchSubs reward.
|
||||||
|
"""
|
||||||
|
ChannelRewardName = "TwitchSub"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(ChannelReward_TwitchSubs.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.twitch_subs)
|
||||||
|
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")
|
||||||
|
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):
|
||||||
|
# todo need to url-escape command and rest
|
||||||
|
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
|
||||||
|
#standalone_lights
|
||||||
|
url = "http://standalone_lights:42069/api/v1/exec_lights?%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 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
|
||||||
@ -24,7 +24,7 @@ class Chyron_Module():
|
|||||||
self.addItem(
|
self.addItem(
|
||||||
"Commands",
|
"Commands",
|
||||||
"► Commands: ",
|
"► Commands: ",
|
||||||
"!animal, !climateclock, !discord, !lights, !page, !roll")
|
"!animal, !climateclock, !discord, !page, !roll")
|
||||||
self.addItem(
|
self.addItem(
|
||||||
"Website",
|
"Website",
|
||||||
"► Want to read about my various projects? visit: ",
|
"► Want to read about my various projects? visit: ",
|
||||||
|
|||||||
@ -6,6 +6,13 @@ from json import loads
|
|||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
import os
|
||||||
|
import praxis_logging
|
||||||
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
|
praxis_logger_obj.init(os.path.basename(__file__))
|
||||||
|
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
|
||||||
|
|
||||||
class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
@ -21,9 +28,19 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
|
|||||||
|
|
||||||
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None):
|
def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None):
|
||||||
returnString = ""
|
returnString = ""
|
||||||
print("\n Command>: " + command + rest)
|
praxis_logger_obj.log("\n Command>: " + command + rest)
|
||||||
|
isTwitch = False
|
||||||
|
|
||||||
returnString = self.dothething(user, 16, command, rest)
|
if source is not None and source == AbstractCommand.CommandSource.Twitch:
|
||||||
|
for user_ in config.allowedCommandsList_TwitchPowerUsers:
|
||||||
|
if user_.lower() == user.lower():
|
||||||
|
praxis_logger_obj.log(user_)
|
||||||
|
praxis_logger_obj.log(user)
|
||||||
|
returnString = self.dothething(user, 16, command, rest)
|
||||||
|
isTwitch = True
|
||||||
|
|
||||||
|
if isTwitch == False:
|
||||||
|
returnString = self.dothething(user, 16, command, rest)
|
||||||
|
|
||||||
return returnString
|
return returnString
|
||||||
|
|
||||||
|
|||||||
@ -80,6 +80,10 @@ dbStrategy = DBStrategy.SQLite
|
|||||||
|
|
||||||
|
|
||||||
#TTS Configs
|
#TTS Configs
|
||||||
|
|
||||||
|
is_tts_Speaker_Enabled = False
|
||||||
|
is_tts_URL_Blocked = True
|
||||||
|
|
||||||
class Speaker(Enum):
|
class Speaker(Enum):
|
||||||
GOOGLE_TEXT_TO_SPEECH = 1
|
GOOGLE_TEXT_TO_SPEECH = 1
|
||||||
STREAMLABS_API = 2
|
STREAMLABS_API = 2
|
||||||
|
|||||||
@ -24,6 +24,14 @@ services:
|
|||||||
- 42069:42069
|
- 42069:42069
|
||||||
environment:
|
environment:
|
||||||
- ISDOCKER=cat
|
- ISDOCKER=cat
|
||||||
|
standalone_tts_core:
|
||||||
|
image: standalone_tts_core
|
||||||
|
volumes:
|
||||||
|
- "./:/Praxis/"
|
||||||
|
ports:
|
||||||
|
- 60809:60809
|
||||||
|
environment:
|
||||||
|
- ISDOCKER=cat
|
||||||
standalone_twitchscript:
|
standalone_twitchscript:
|
||||||
image: standalone_twitchscript
|
image: standalone_twitchscript
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
docker build --file Dockerfile_standalone_command --tag standalone_command .
|
docker build --file Dockerfile_standalone_command --tag standalone_command .
|
||||||
docker build --file Dockerfile_standalone_channelRewards --tag standalone_channelrewards .
|
docker build --file Dockerfile_standalone_channelRewards --tag standalone_channelrewards .
|
||||||
docker build --file Dockerfile_standalone_lights --tag standalone_lights .
|
docker build --file Dockerfile_standalone_lights --tag standalone_lights .
|
||||||
|
docker build --file Dockerfile_standalone_tts_core --tag standalone_tts_core .
|
||||||
docker build --file Dockerfile_standalone_DiscordScript --tag standalone_discordscript .
|
docker build --file Dockerfile_standalone_DiscordScript --tag standalone_discordscript .
|
||||||
docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript .
|
docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript .
|
||||||
docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub .
|
docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub .
|
||||||
@ -94,10 +94,20 @@ class Lights_Module():
|
|||||||
def setGroups():
|
def setGroups():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def rubiksCube(self):
|
||||||
|
for rave in range(10):
|
||||||
|
rgb_r = random.random()
|
||||||
|
rgb_g = random.random()
|
||||||
|
rgb_b = random.random()
|
||||||
|
xy_result = self.rgb_to_xy(rgb_r, rgb_g, rgb_b) #This will take an rgb value and make it xy
|
||||||
|
self.bridge_.set_group(16, "xy", xy_result, transitiontime=0.2)
|
||||||
|
sleep(0.25)
|
||||||
|
self.bridge_.run_scene("Downstairs", "Stream")
|
||||||
|
|
||||||
def hydration(self):
|
def hydration(self):
|
||||||
self.bridge_.run_scene("Downstairs", "hydration")
|
self.bridge_.run_scene("Downstairs", "hydration")
|
||||||
#sleep(20)
|
sleep(4)
|
||||||
#self.bridge_.run_scene("Downstairs", "Stream")
|
self.bridge_.run_scene("Downstairs", "Stream")
|
||||||
|
|
||||||
def raveMode(self):
|
def raveMode(self):
|
||||||
for rave in range(30):
|
for rave in range(30):
|
||||||
@ -250,6 +260,9 @@ def do_lights_command(user="", lightGroup="all", command = "", rest = ""):
|
|||||||
elif "on" in tempParsedMessage:
|
elif "on" in tempParsedMessage:
|
||||||
sceneCommand = True
|
sceneCommand = True
|
||||||
RGB_Lights.bridge_.set_group("Downstairs", "on", True)
|
RGB_Lights.bridge_.set_group("Downstairs", "on", True)
|
||||||
|
elif "rubikscube" in tempParsedMessage:
|
||||||
|
sceneCommand = True
|
||||||
|
RGB_Lights.rubiksCube()
|
||||||
elif "hydration" in tempParsedMessage:
|
elif "hydration" in tempParsedMessage:
|
||||||
sceneCommand = True
|
sceneCommand = True
|
||||||
RGB_Lights.hydration()
|
RGB_Lights.hydration()
|
||||||
|
|||||||
54
standalone_tts_core.py
Normal file
54
standalone_tts_core.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import flask
|
||||||
|
from flask import request
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
import os
|
||||||
|
import praxis_logging
|
||||||
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
|
praxis_logger_obj.init(os.path.basename(__file__))
|
||||||
|
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
|
||||||
|
|
||||||
|
api = flask.Flask(__name__)
|
||||||
|
# enable/disable this to get web pages of crashes returned
|
||||||
|
api.config["DEBUG"] = True
|
||||||
|
|
||||||
|
def init():
|
||||||
|
praxis_logger_obj.log("init stuff")
|
||||||
|
|
||||||
|
def send_text(tts_sender, tts_text):
|
||||||
|
|
||||||
|
#Play Text
|
||||||
|
params = urlencode({'tts_sender': tts_sender, 'tts_text': tts_text})
|
||||||
|
|
||||||
|
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:
|
||||||
|
# todo handle failed requests
|
||||||
|
#pass
|
||||||
|
|
||||||
|
#return None
|
||||||
|
return flask.make_response('', 200)
|
||||||
|
|
||||||
|
@api.route('/api/v1/tts/send_text', methods=['GET'])
|
||||||
|
def tts_send_text():
|
||||||
|
if 'tts_sender' not in request.args:
|
||||||
|
tts_sender = ""
|
||||||
|
if 'tts_text' not in request.args:
|
||||||
|
return flask.make_response('{\"text\":"Argument \'tts_text\' not in request"}', 400)
|
||||||
|
|
||||||
|
return send_text(request.args['tts_sender'], request.args['tts_text'])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#send_text("","Blah Blah Blah")
|
||||||
|
#init()
|
||||||
|
api.run(host='0.0.0.0', port=60809)
|
||||||
68
standalone_tts_speaker.py
Normal file
68
standalone_tts_speaker.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import flask
|
||||||
|
from flask import request
|
||||||
|
|
||||||
|
import tts
|
||||||
|
|
||||||
|
import config
|
||||||
|
import utilities_script as utility
|
||||||
|
|
||||||
|
import os
|
||||||
|
import praxis_logging
|
||||||
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
|
praxis_logger_obj.init(os.path.basename(__file__))
|
||||||
|
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
|
||||||
|
|
||||||
|
api = flask.Flask(__name__)
|
||||||
|
# enable/disable this to get web pages of crashes returned
|
||||||
|
api.config["DEBUG"] = False
|
||||||
|
|
||||||
|
def init():
|
||||||
|
praxis_logger_obj.log("init stuff")
|
||||||
|
|
||||||
|
def isTTS_URL_Check(message):
|
||||||
|
isNotBlocked = True
|
||||||
|
is_ttsEnabled = config.is_tts_Speaker_Enabled
|
||||||
|
is_tts_URL_Allowed = not config.is_tts_URL_Blocked
|
||||||
|
has_URL = False
|
||||||
|
if utility.contains_url(message):
|
||||||
|
has_URL = True
|
||||||
|
|
||||||
|
if is_tts_URL_Allowed:
|
||||||
|
if has_URL:
|
||||||
|
has_URL = False
|
||||||
|
if has_URL:
|
||||||
|
isNotBlocked = False
|
||||||
|
if not is_ttsEnabled:
|
||||||
|
isNotBlocked = False
|
||||||
|
|
||||||
|
return not isNotBlocked
|
||||||
|
|
||||||
|
def try_TTS(tts_sender, tts_text):
|
||||||
|
text_to_say: str = "%s says, %s" % (tts_sender, tts_text)
|
||||||
|
|
||||||
|
#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(str(text_to_say))
|
||||||
|
|
||||||
|
return flask.make_response('', 200)
|
||||||
|
|
||||||
|
@api.route('/api/v1/tts/speech', methods=['GET'])
|
||||||
|
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(tts_sender, request.args['tts_text'])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#init()
|
||||||
|
api.run(host='0.0.0.0', port=40085)
|
||||||
Loading…
Reference in New Issue
Block a user