Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Config/ArmRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def __init__(self):
self.console_input: ConsoleInput = ConsoleInput()

def apply_config(self, config: Dict[str, Any]) -> None:
if config["write_logs"]:
if config.get("write_logs", False):
from Modules.Logging.PrintLogger import PrintLogger
self.selected_logger = PrintLogger()
self.selected_logger.start()

if config["use_tts"]:
if config.get("use_tts", False):
from Modules.text_to_speech.TTSBase import TTSBase
from Modules.text_to_speech.pyttsx_tts import pyttsx_tts
self.selected_tts: TTSBase = pyttsx_tts()
Expand All @@ -57,7 +57,7 @@ def console_input_handeler(input_str: str) -> None:
register_controler_commands(self.commands, lambda: self.selected_controller)

# Language stuff
if config["use_language_model"]:
if config.get("use_language_model", False):
from Modules.Language.LanguageInterpreter import LanguageInterpreter
print("language_model_file: \"" + str(config["language_model_file"]) + "\"")
self.selected_language_interpreter = LanguageInterpreter(config["language_model_file"])
Expand All @@ -66,13 +66,13 @@ def console_input_handeler(input_str: str) -> None:
self.commands.add_command("llm", lambda args: self.selected_voice.write_line(self.selected_language_interpreter.run(args)),
"Runs the provided input on the language model")
# HAL stuff
if config["use_simulator_hal"]:
if config.get("use_simulator_hal", False):
from HALs.sim_HAL import sim_HAL
self.selected_HAL = sim_HAL(config["sim_host"])
elif config["use_physical_hal"]:
elif config.get("use_physical_hal", False):
from HALs.physical_HAL import physical_HAL
self.selected_HAL = physical_HAL()
elif config["use_remote_hal"]:
elif config.get("use_remote_hal", False):
if "remote_hal_ip" not in config or not config["remote_hal_ip"]:
print("ERROR: 'remote_hal_ip' is missing or invalid in the configuration.")
elif "remote_hal_port" not in config or not config["remote_hal_port"]:
Expand All @@ -98,7 +98,7 @@ def console_input_handeler(input_str: str) -> None:
self.selected_controller: Controller = FollowLargestObjectControler(self.selected_HAL, self.selected_object_identifier, "none")

# App stuff
if config["use_app"]:
if config.get("use_app", False):
# Kivy opens the window if this is imported, thus why it is here.
from Modules.App.App import App
from Controllers.FollowClaw import FollowClawController
Expand All @@ -107,7 +107,7 @@ def console_input_handeler(input_str: str) -> None:
self.selected_app = App(self.selected_controller, self.selected_HAL, self.selected_object_identifier)

# Server setup
if config["use_server"]:
if config.get("use_server", False):
from Modules.server.http_server import HTTPServer
new_host_port: int = 8000
if "server_host_port" in config:
Expand All @@ -118,18 +118,18 @@ def console_input_handeler(input_str: str) -> None:
self.selected_server: ServerBase = HTTPServer(self, new_host_port)

# speech to text setup
if config["use_stt"]:
if config.get("use_stt", False):
from Modules.speech_to_text.VoskSTT import VoskSTT

def speech_input_handeler(input_str: str) -> None:
self.commands.user_input(input_str, Commands.Trust.TRUSTED, self.selected_stt)

self.selected_stt: STTBase = VoskSTT(on_sentence_heard_fnc = speech_input_handeler)
if config["stt_model_large"]:
if config.get("stt_model_large", False):
self.selected_stt.set_selected_default_model(VoskSTT.DEFAULT_MODEL_LARGE)

self.selected_stt.start()
if config["stt_push_to_talk"]:
if config.get("stt_push_to_talk", False):
print("Speech Recognition is in push to talk mode - press left-shift to activate")
def stt_activate():
if not self.selected_stt.is_active():
Expand All @@ -144,7 +144,7 @@ def stt_deactivate():
self.hotkey_manager.add_key_release_callback(keyboard.Key.shift, stt_deactivate)

# Twitch setup
if config["use_twitch"]:
if config.get("use_twitch", False):
from Modules.twitch.TwitchChat import TwitchChat
if config["twitch_id"] == "NONE":
print("Please set twitch_id to a valid twitch_id to use the twitch chat reader")
Expand All @@ -155,7 +155,7 @@ def stt_deactivate():

def start(self, config: Dict[str, Any]) -> None:
# Connect to twitch
if config["use_twitch"]:
if config.get("use_twitch", False):
def twitch_input_handeler(input_str: str) -> None:
self.commands.user_input(input_str, Commands.Trust.SUS, self.selected_twitch)

Expand All @@ -165,7 +165,7 @@ def twitch_input_handeler(input_str: str) -> None:

def stop(self, config: Dict[str, Any]) -> None:
self.hotkey_manager.stop()
if config["use_twitch"]:
if config.get("use_twitch", False):
self.selected_twitch.stop_twitch_chat()

self.console_input.cleanup()
Expand Down
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
armRuntime.start(config) # start the rest of the modules

# start listening to speech
if armRuntime.selected_stt is not None and not config["stt_push_to_talk"]:
if armRuntime.selected_stt is not None and not config.get("stt_push_to_talk", False):
armRuntime.selected_stt.activate()

if armRuntime.selected_tts is not None:
Expand All @@ -47,20 +47,20 @@

# ----------------- MAIN PROGRAM LOOP -----------------
# will capture main thread and run the input loop in a separate thread
if config["use_server"]:
if config.get("use_server", False):
print("Server Startup")
armRuntime.selected_server.start_server()

# will capture main thread and run the input loop in a separate thread
if config["use_app"]:
if config.get("use_app", False):
try:
armRuntime.console_input.run_input_looping_async()
armRuntime.selected_app.start_app()
except KeyboardInterrupt:
keep_running = False

# if we are not using the server or the app, we will run the input loop in the main thread
if not config["use_app"]:
if not config.get("use_app", False):
while keep_running:
print("Arm is running, press 'q' or ctrl-c to quit")
try:
Expand Down Expand Up @@ -100,7 +100,7 @@
print("Arm shutdown complete")

# Reopen Startup page
if config["open_startup_page"]:
if config.get("open_startup_page", False):
subprocess.Popen(['python', 'ArmTeam/startup.py'])

# ----------------- END CLEAUP / SHUTDOWN -----------------