From d683239e4e7718548b79c4e8e7e58c0f762b047d Mon Sep 17 00:00:00 2001 From: Colton Loftus <70598503+C-Loftus@users.noreply.github.com> Date: Fri, 17 May 2024 18:45:51 -0400 Subject: [PATCH] improve mode speaking on context switch (#34) --- core/callbacks.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/core/callbacks.py b/core/callbacks.py index 5887014..f405da8 100644 --- a/core/callbacks.py +++ b/core/callbacks.py @@ -64,21 +64,22 @@ def on_update_contexts(): COMMAND = "command" in modes and "dictation" not in modes DICTATION = "dictation" in modes and "command" not in modes SLEEP = "sleep" in modes - ANNOUNCE = settings.get("user.announce_mode_updates") + + + speak = actions.user.echo_dictation_enabled() and settings.get("user.announce_mode_updates") + message_to_speak: str = "" if last_mode == "sleep" and not SLEEP: - # Always announce wake up # Cancel any current speaker, weird edge case where it will speak twice otherwise actions.user.cancel_current_speaker() - actions.user.tts("Talon now listening") + message_to_speak = "Talon listening" elif last_mode != "sleep" and SLEEP: # Always announce sleep - actions.user.tts("Talon asleep") + message_to_speak = "Talon asleep" elif last_mode != "sleep" and MIXED and last_mode != "mixed": - if ANNOUNCE: - actions.user.tts("Talon mixed mode") + message_to_speak = "Talon mixed mode" elif ( last_mode != "sleep" @@ -87,8 +88,7 @@ def on_update_contexts(): and not SLEEP and last_mode != "command" ): - if ANNOUNCE: - actions.user.tts("Talon command mode") + message_to_speak = "Talon command mode" elif ( last_mode != "sleep" @@ -98,8 +98,7 @@ def on_update_contexts(): and last_mode != "dictation" and last_mode != "mixed" ): - if ANNOUNCE: - actions.user.tts("Talon dictation mode") + message_to_speak = "Talon dictation mode" if SLEEP: CallbackState.last_mode = "sleep" @@ -110,6 +109,9 @@ def on_update_contexts(): elif DICTATION: CallbackState.last_mode = "dictation" + if speak and message_to_speak != "": + actions.user.tts(message_to_speak) + def on_ready(): # Only register these callbacks once all user settings and Talon @@ -121,7 +123,11 @@ def on_ready(): if settings.get("user.start_screenreader_on_startup"): actions.user.toggle_reader() - actions.user.tts("Talon user scripts loaded") + + # We don't have a setting specifically for echoing at startup + # but we can still use the same setting since it is semantically relevant + if actions.user.echo_dictation_enabled(): + actions.user.tts("Talon user scripts loaded") app.register("ready", on_ready)