From a04f971a84299ceefb8f22fb58f8f8e6b71b1025 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:50:34 +0000 Subject: [PATCH] feat/console_scripts (#105) * feat/console_scripts each method here is a entrypoint define in setup.py, each corresponds to a cli util ``` entry_points={ 'console_scripts': [ 'ovos-listen=ovos_utils.scripts:ovos_listen', 'ovos-speak=ovos_utils.scripts:ovos_speak', 'ovos-say_to=ovos_utils.scripts:ovos_say_to', ] } ``` * typo --- ovos_utils/scripts.py | 45 +++++++++++++++++++++++++++++++++++++++++++ setup.py | 9 ++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ovos_utils/scripts.py diff --git a/ovos_utils/scripts.py b/ovos_utils/scripts.py new file mode 100644 index 00000000..fa693ae9 --- /dev/null +++ b/ovos_utils/scripts.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# each method here is a console_script defined in setup.py +# each corresponds to a cli util +from mycroft_bus_client import MessageBusClient, Message +from ovos_config import Configuration +import sys + + +def ovos_speak(): + if (args_count := len(sys.argv)) == 2: + utt = sys.argv[1] + lang = Configuration().get("lang", "en-us") + elif args_count == 3: + utt = sys.argv[1] + lang = sys.argv[2] + else: + print("USAGE: ovos-speak {utterance} [lang]") + raise SystemExit(2) + client = MessageBusClient() + client.run_in_thread() + client.emit(Message("speak", {"utterance": utt, "lang": lang})) + client.close() + + +def ovos_say_to(): + if (args_count := len(sys.argv)) == 2: + utt = sys.argv[1] + lang = Configuration().get("lang", "en-us") + elif args_count == 3: + utt = sys.argv[1] + lang = sys.argv[2] + else: + print("USAGE: ovos-say-to {utterance} [lang]") + raise SystemExit(2) + client = MessageBusClient() + client.run_in_thread() + client.emit(Message("recognizer_loop:utterance", {"utterances": [utt], "lang": lang})) + client.close() + + +def ovos_listen(): + client = MessageBusClient() + client.run_in_thread() + client.emit(Message("mycroft.mic.listen")) + client.close() diff --git a/setup.py b/setup.py index c8e7aa5e..a5a5fa06 100644 --- a/setup.py +++ b/setup.py @@ -70,5 +70,12 @@ def required(requirements_file): license='Apache', author='jarbasAI', author_email='jarbasai@mailfence.com', - description='collection of simple utilities for use across the mycroft ecosystem' + description='collection of simple utilities for use across the mycroft ecosystem', + entry_points={ + 'console_scripts': [ + 'ovos-listen=ovos_utils.scripts:ovos_listen', + 'ovos-speak=ovos_utils.scripts:ovos_speak', + 'ovos-say-to=ovos_utils.scripts:ovos_say_to', + ] + } )