Skip to content

Commit

Permalink
add simple_cli entrypoint (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Oct 16, 2023
1 parent e49c451 commit f3659c2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ovos_bus_client/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -36,12 +38,53 @@ 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()


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()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
)

0 comments on commit f3659c2

Please sign in to comment.