Skip to content

Commit

Permalink
clean up settings and begin override
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Dec 19, 2023
1 parent 8e6824f commit 8c6a7eb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
42 changes: 24 additions & 18 deletions core/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,73 @@

def on_phrase(parsed_phrase):
if actions.speech.enabled() and actions.user.echo_dictation_enabled():
words = parsed_phrase.get('text')
words = parsed_phrase.get("text")
if words:
command_chain = ' '.join(words)
command_chain = " ".join(words)

# Not all tts engines support canceling
# Easier to just catch the exception
try:
actions.user.cancel_current_speaker()
except Exception as e:
pass

actions.user.robot_tts(command_chain)

if settings.get("user.braille_output"):
actions.user.braille(command_chain)

speech_system.register('phrase', on_phrase)

def on_app_switch(app):
if not actions.user.echo_context_enabled():
return
return
actions.user.echo_context()


# We have to keep track of the last title so we don't repeat it
# since sometimes Talon triggers a "title switch" when
# since sometimes Talon triggers a "title switch" when
# the title actually hasn't changed, i.e. when a text file is saved
last_title = None
def on_title_switch(win):
if not actions.user.echo_context_enabled():
return
return
window = ui.active_window()
active_window_title = window.title
# get just the first two words
active_window_title = ' '.join(active_window_title.split()[:2])
#trime the title to 20 characters so super long addresses don't get read
active_window_title = " ".join(active_window_title.split()[:2])
# trime the title to 20 characters so super long addresses don't get read
active_window_title = active_window_title[:20]

global last_title
if last_title == active_window_title:
return

last_title = active_window_title
actions.user.robot_tts(f"{active_window_title}")


last_mode = None
def on_update_contexts():
global last_mode
modes = scope.get("mode") or []
if last_mode == 'sleep' and 'sleep' not in modes:
actions.user.robot_tts(f'Talon has woken up')
elif last_mode != 'sleep' and 'sleep' in modes:
actions.user.robot_tts(f'Talon has gone to sleep')
if last_mode == "sleep" and "sleep" not in modes:
actions.user.robot_tts(f"Talon has woken up")
elif last_mode != "sleep" and "sleep" in modes:
actions.user.robot_tts(f"Talon has gone to sleep")
last_mode = "sleep" if "sleep" in modes else "other"



def on_ready():
# Only register these callbacks once all user settings and Talon
# files have been loaded
registry.register("update_contexts", on_update_contexts)
ui.register("app_activate", on_app_switch)
ui.register("win_title", on_title_switch)
speech_system.register("phrase", on_phrase)

if settings.get("user.start_screenreader_on_startup"):
actions.user.toggle_reader()
actions.user.robot_tts("Talon user scripts loaded")


app.register("ready", on_ready)
registry.register("update_contexts", on_update_contexts)
ui.register("app_activate", on_app_switch)
ui.register("win_title", on_title_switch)
9 changes: 9 additions & 0 deletions core/overrides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from talon import Module, actions, Context

soundContext = Context()

class ActionClass:
def key(key: str):
"""Presses a key"""
actions.beep()
actions.next(key)
7 changes: 7 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,12 @@
desc="The volume of the text to speech",
)

mod.setting(
"tone_on_keypress",
type=bool,
default=False,
desc="If True, plays a tone on keypress to reduce the impact of accidental keypresses",
)

mod.mode("strict_dictation", desc="Dictation mode with only a subset of dictation commands")
mod.mode('strict_command', desc='Command mode with only a subset of command commands')
30 changes: 15 additions & 15 deletions sight-free-settings.talon
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
settings():
# echo the subtitles from talon back via tts
# Echo the subtitles from talon back via tts
user.echo_dictation = true

# how fast to play back text-to-speech
# if using the windows native tts. If
# using the screenreader tts, this setting
# is ignored and the screenreader's tts is used
# How fast to play back text-to-speech
# Ignored if using screenreader tts
user.tts_speed = 6

# 1 through 100 (Not used if using screenreader tts)
# How loud to play back text-to-speech from 0 to 100
# Ignored if using screenreader tts
user.tts_volume = 80

# Automatically echo the context of the focused window when switching applications/tabs
user.echo_context = false

# instead of playing tts via talon, play it via the tts engine in your screenreader
# If a screen reader is enabled, use it for tts instead of the TTS engine in Talon
user.tts_via_screenreader = true

# key used for nvda modifier, change to 'insert' if that is your nvda modifier
# Key used for nvda modifier, change to 'insert' if that is your nvda modifier
user.nvda_key = 'capslock'

# Starts NVDA automatically with Talon
user.start_screenreader_on_startup = false

# setting from community repository
# Manually typing keys through Talon can jumble the audio output since nvda can also say out
# keys and/or words. By having this setting enabled, we can echo out the text but
# not need to disable the screenreader's speech for characters and words for normal typing
# user.paste_to_insert_threshold = -1

# Requires screen reader
# Output dictated text to braille display through your screen reader
user.braille_output = false

### Relevant Community Settings Below ###
# Change key_wait if you want the screen reader to speak words
# at the same pace as if you were typing them manually.
# key_wait = 0

# Setting from community repository
# Manually typing keys through Talon can jumble the audio output since nvda can also say out
# keys and/or words. By having this setting enabled, we can echo out the text but
# not need to disable the screenreader's speech for characters and words for normal typing
# user.paste_to_insert_threshold = -1

0 comments on commit 8c6a7eb

Please sign in to comment.