From f3659c2bd7332cc28e3a191c919658fdaf172b79 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Mon, 16 Oct 2023 19:37:21 +0100 Subject: [PATCH] add simple_cli entrypoint (#56) --- ovos_bus_client/scripts.py | 43 ++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 2 files changed, 44 insertions(+) diff --git a/ovos_bus_client/scripts.py b/ovos_bus_client/scripts.py index 78ad421..997d489 100644 --- a/ovos_bus_client/scripts.py +++ b/ovos_bus_client/scripts.py @@ -19,6 +19,8 @@ def ovos_speak(): raise SystemExit(2) client = MessageBusClient() client.run_in_thread() + if not client.connected_event.is_set(): + client.connected_event.wait() client.emit(Message("speak", {"utterance": utt, "lang": lang})) client.close() @@ -36,6 +38,8 @@ def ovos_say_to(): raise SystemExit(2) client = MessageBusClient() client.run_in_thread() + if not client.connected_event.is_set(): + client.connected_event.wait() client.emit(Message("recognizer_loop:utterance", {"utterances": [utt], "lang": lang})) client.close() @@ -43,5 +47,44 @@ def ovos_say_to(): def ovos_listen(): client = MessageBusClient() client.run_in_thread() + if not client.connected_event.is_set(): + client.connected_event.wait() client.emit(Message("mycroft.mic.listen")) client.close() + + +def simple_cli(): + args_count = len(sys.argv) + if args_count == 1: + lang = Configuration().get("lang", "en-us") + elif args_count == 2: + lang = sys.argv[1] + else: + print("USAGE: ovos-simple-cli [lang]") + return + + client = MessageBusClient() + client.run_in_thread() + if not client.connected_event.is_set(): + client.connected_event.wait() + lang = lang or Configuration().get("lang", "en-us") + + from ovos_bus_client.session import SessionManager, Session + sess = SessionManager.default_session + + while True: + try: + utt = input("Say:") + if utt == ":exit": + break + client.emit(Message("recognizer_loop:utterance", + {"utterances": [utt], "lang": lang}, + {"session": sess.serialize()})) + except KeyboardInterrupt: + break + + client.close() + + +if __name__ == "__main__": + simple_cli() \ No newline at end of file diff --git a/setup.py b/setup.py index 80a3209..4005343 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ def get_version(): 'ovos-listen=ovos_bus_client.scripts:ovos_listen', 'ovos-speak=ovos_bus_client.scripts:ovos_speak', 'ovos-say-to=ovos_bus_client.scripts:ovos_say_to', + 'ovos-simple-cli=ovos_bus_client.scripts:simple_cli' ] } )