Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Jan 4, 2024
1 parent 9343c0b commit 5985342
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 12 deletions.
21 changes: 21 additions & 0 deletions application-integration/chat-gpt-browser.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
title: /https://chat.openai.com/

-
Open new chat: key(ctrl-shift-o)
Focus chat input: key(shift-esc)
Copy last code block: key(ctrl-shift-;)
Copy last response: key(ctrl-shift-c)

speak [last] ( response | output | chat ):
key(ctrl-shift-c)
sleep(0.3)
user.tts(clip.text())

speak last code [block]:
key(ctrl-shift-;)
sleep(0.3)
user.tts(clip.text())

Set custom instructions: key(ctrl-shift-i)
Toggle sidebar: key(ctrl-shift-s)
Delete chat: key(ctrl-shift-delete)
9 changes: 4 additions & 5 deletions application-integration/gpt-utils.talon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ tag: user.openai_defined

-

# TODO: This is currently dependent upon my own implementation, going forward
# I need to check if there's going to be some sort of community standard and how
# it might be best to integrate my code with a broader more community based solution
^echo {user.promptNoArgument}$:
result = user.gpt_prompt_no_argument(user.promptNoArgument)
# Uses Talon-AI-Tools community standard
^echo {user.staticPrompt}$:
text = edit.selected_text()
result = user.gpt_apply_prompt(user.staticPrompt, text)
user.cancel_current_speaker()
user.tts(result)

Expand Down
7 changes: 4 additions & 3 deletions core/core-agnostic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
This file contains actions that are core to the talon tts system
and are agnostic to the tts engine being used or the operating system
and are agnostic to the tts voice being used or the operating system
"""

from typing import Optional
from talon import Module, actions, Context, settings, app

from talon import Module, actions, Context, settings, app

mod = Module()
ctx = Context()
Expand Down Expand Up @@ -98,9 +97,11 @@ def tts(text: str):

def espeak(text: str):
'''text to speech with espeak'''
actions.user.tts("Espeak Not Supported In This Context")

def toggle_reader():
"""Toggles the screen reader on and off"""
actions.user.tts("Toggle Reader Not Supported In This Context")

def base_win_tts(text: str):
"""Base function for windows tts. We expose this
Expand Down
2 changes: 1 addition & 1 deletion core/core-windows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import Context, settings
from talon import Context, settings, actions
import os

from .sapi import SAPI5
Expand Down
2 changes: 2 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@
mod.setting("min_until_break", type=int, default=10)
# mod.setting("break_length", type=int, default=10)

mod.setting("orca_key", type=str, default="capslock")

# 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')
2 changes: 2 additions & 0 deletions docs/src/ATTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- [https://github.com/nvaccess/nvda/wiki/](https://github.com/nvaccess/nvda/wiki/)
- [ https://addons.nvda-project.org/addons/AudioThemes.en.html](https://addons.nvda-project.org/addons/AudioThemes.en.html)
- [https://addons.nvda-project.org/addons/phoneticPunctuation.en.html] (https://addons.nvda-project.org/addons/phoneticPunctuation.en.html)
- Helpful settings
- Document Formatting: "Line Indentation Reporting" set to "Tones"

## Libraries

Expand Down
4 changes: 3 additions & 1 deletion docs/src/philosophy.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- Less is more: Prioritize Plain Text -->

# Accessibility Design alongside Chronic Pain

Within digital accessibility, designers often assume conditions that are static binaries. for instance either a user is either blind or sighted. If a user has a vision impairment, designers often implicitly expect it to be a permanent condition, not one that might fluctuate based on pain levels.
Expand All @@ -6,7 +8,7 @@ When designing around chronic pain, all of these assumptions are knocked down. f

The unconscious mind is often not rational in the long term and it will easily pick a moderately uncomfortable solution if it can be done quickly with little friction. however as anyone with chronic pain knows, enough of these moderately uncomfortable actions can quickly accumulate two a flare up of significant pain.

As such when we are designing around chronic pain we can't simply look at baseline accessibility. we need to have designs that are such low friction and in some way do something totally unique that the old way of computer interaction couldn't do.
As such when we are designing around chronic pain we can't simply look at baseline accessibility. We need to have designs that are such low friction and in some way do something totally unique that the old way of computer interaction couldn't do.

# For Better Accessibility, Do Less

Expand Down
55 changes: 55 additions & 0 deletions nvda/nvda-parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os, configparser
from talon import actions, Module, Context

PATH = os.path.expanduser("~\\AppData\\Roaming\\nvda\\nvda.ini")

"""
Read in and parse the nvda.ini file, then write back to it.
We need to skip the first line of the file, which is a schema version
and would otherwise cause the configparser to fail since it isn't valid ini
"""


mod = Module()
@mod.action_class
class Actions:
def nvda_set_setting(setting: str, value: bool):
"""Sets an NVDA setting to a given value"""

ctx = Context()
ctx.matches = r"""
os: windows
"""

@ctx.action_class("user")
class UserActions:
def nvda_set_setting(setting: str, value: bool):

# Load the nvda.ini file, skipping the first line
with open(PATH, 'r') as f:
next(f) # Skip the first line
config_string = f.read()

config = configparser.RawConfigParser()
config.optionxform = str
config.read_string(config_string)

# Search for the speakTypedWords setting in all sections
for section in config.sections():
if setting in config[section]:
config[section][setting] = str(value)

# Save the changes back to the nvda.ini file, preserving the first line
with open(PATH, 'r') as f:
first_line = next(f) # Save the first line

with open(PATH, 'w') as configfile:
configfile.write(first_line) # Write the first line back to the file
config.write(configfile) # Write the rest of the config
print(f"Set NVDA setting: {setting} to {value}")
actions.user.with_nvda_mod_press("ctrl-r")


# cron.after then refresh after the dictation is done. Hard to figure out
# how to do this though since we don't have a callback for when the dictatio
# is done.
2 changes: 2 additions & 0 deletions nvda/nvda-settings.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# speak typed words: user.nvda_set_setting("speakTypedWords", True)
# computer: user.nvda_set_setting("speakTypedCharacters", false)
13 changes: 12 additions & 1 deletion nvda/nvda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import actions, Module, settings, cron, Context, clip, registry, app
from talon import actions, Module, settings, cron, Context, clip, registry, app , speech_system
import os, ctypes, time

mod = Module()
Expand Down Expand Up @@ -107,3 +107,14 @@ def braille(text: str):
"""Output braille with NVDA"""
nvda_client.nvdaController_brailleMessage(text)



# Not sure how to usually have speak words on
# since if we have it on all the time then it will mess
# def toggle_speak_typed_words(_):
# """Toggles the speak typed words setting"""
# actions.user.with_nvda_mod_press("3")

# speech_system.register("pre:phrase", toggle_speak_typed_words)
# speech_system.register("post:phrase", toggle_speak_typed_words)

12 changes: 12 additions & 0 deletions orca/orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def is_orca_running() -> bool:
def orca_tts(text: str, use_clipboard: bool= False):
'''text to speech with orca'''

def with_orca_mod_press(key: str):
''' Presses the given key with the orca modifier key'''


ctxLinux = Context()
ctx.matches = r"""
Expand All @@ -46,6 +49,15 @@ def toggle_reader():
return

actions.key("alt-super-s")

def with_orca_mod_press(key: str):
''' Presses the given key with the orca modifier key'''
orca_key = settings.get("user.orca_key")
actions.key(f'{orca_key}:down')
actions.sleep("50ms")
actions.key(key)
actions.sleep("10ms")
actions.key(f'{orca_key}:up')

ctxorcaRunning = Context()
ctxorcaRunning.matches = r"""
Expand Down
55 changes: 54 additions & 1 deletion utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
from talon import Module, actions, ui, Context, ctrl, clip, registry
from talon import Module, actions, ui, Context, ctrl, clip, registry, scope
import os, requests
from html.parser import HTMLParser
import urllib

from ..lib.HTMLbuilder import HTMLBuilder
import threading

class VisibleTextParser(HTMLParser):
def __init__(self):
super().__init__()
self.text = []
self.ignore = False
self.ignore_tags = ['style', 'script', 'head', 'title', 'meta', '[document]']

def handle_starttag(self, tag, attrs):
if tag in self.ignore_tags:
self.ignore = True

def handle_endtag(self, tag):
if tag in self.ignore_tags:
self.ignore = False

def handle_data(self, data):
if not self.ignore:
self.text.append(data.strip())


mod = Module()

if os.name == 'nt':
Expand Down Expand Up @@ -77,6 +99,37 @@ def explore_modes():
def extract_text():
"""Extract the text from the current window"""

def echo_mode():
"""Echo the current modes"""
modes = scope.get("mode")
# if dictation or command is in the modes, say that first
if "dictation" in modes and "command" in modes:
actions.user.tts("mixed")
elif "dictation" in modes:
actions.user.tts("dictation")
elif "command" in modes:
actions.user.tts("command")

def get_website_text(url: str) -> str:
"""Get the visible text from a website"""
try:
# Download HTML content
with urllib.request.urlopen(url) as response:
html_content = response.read()

# Parse HTML and extract visible text
parser = VisibleTextParser()
parser.feed(html_content.decode('utf-8', errors='ignore'))

# Combine and return the visible text
return ' '.join(parser.text)

except Exception as e:
print("Error Parsing:", e)
return f"Error Parsing"




ctxWindows = Context()
ctxWindows.matches = r"""
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.talon
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ explore tags:

explore settings:
user.explore_settings()

echo mode:
user.echo_mode()

echo website:
key(ctrl-l)
sleep(0.3)
edit.copy()
text = user.get_website_text(clip.text())
user.tts(text)
key(escape)

0 comments on commit 5985342

Please sign in to comment.