示例#1
0
speech = actions.speech

module = Module()


@module.action_class
class Actions:
    def sleep():
        """Sleep speech recognition."""
        speech.disable()

    def wake():
        """Wake speech recognition."""
        speech.enable()

    def engine_mimic(phrase: str):
        """Force the engine to mimic a phrase"""
        speech_system.engine_mimic(phrase)


dragon_context = Context("user.dragon_context")
dragon_context.matches = r"""
tag: user.dragon
"""


@dragon_context.action_class("self")
class DragonActions:
    def sleep():
        speech_system.engine_mimic("go to sleep")
示例#2
0
from talon import speech_system, Context
from talon.engines.w2l import WebW2lEngine, W2lEngine
from talon.engines.webspeech import WebSpeechEngine

w2l = W2lEngine(model='en_US-conformer', debug=False)
speech_system.add_engine(w2l)
webspeech = WebSpeechEngine()
speech_system.add_engine(webspeech)  # set the default engine

ctx = Context()
ctx.settings = {
    'speech.engine': 'wav2letter',
}
示例#3
0
from talon import Module, Context, ui, actions, clip, app, grammar
from typing import Optional, Tuple, Literal, Callable
import re

mod = Module()

setting_context_sensitive_dictation = mod.setting(
    "context_sensitive_dictation",
    type=bool,
    default=False,
    desc="Look at surrounding text to improve auto-capitalization/spacing in dictation mode. By default, this works by selecting that text & copying it to the clipboard, so it may be slow or fail in some applications.",
)

mod.list("prose_modifiers", desc="Modifiers that can be used within prose")
mod.list("prose_snippets", desc="Snippets that can be used within prose")
ctx = Context()
# Maps spoken forms to DictationFormat method names (see DictationFormat below).
ctx.lists["user.prose_modifiers"] = {
    "cap": "cap",
    "no cap": "no_cap",
    "no caps": "no_cap", # "no caps" variant for Dragon
    "no space": "no_space",
}
ctx.lists["user.prose_snippets"] = {
    "spacebar": " ",
    "new line": "\n",
    "new paragraph": "\n\n",
    # Curly quotes are used to obtain proper spacing for left and right quotes, but will later be straightened.
    "open quote": "“",
    "close quote": "”",
    "smiley": ":-)",
STALE_TIMEOUT_MS = 60_000

# The amount of time to wait for VSCode to perform a command, in seconds
VSCODE_COMMAND_TIMEOUT_SECONDS = 3.0

# When doing exponential back off waiting for vscode to perform a command, how
# long to sleep the first time
MINIMUM_SLEEP_TIME_SECONDS = 0.0005

# Indicates whether a pre-phrase signal was emitted during the course of the
# current phrase
did_emit_pre_phrase_signal = False

mod = Module()

global_ctx = Context()
ctx = Context()
mac_ctx = Context()
linux_ctx = Context()

ctx.matches = r"""
app: vscode
"""
mac_ctx.matches = r"""
os: mac
app: vscode
"""
linux_ctx.matches = r"""
os: linux
app: vscode
"""
示例#5
0
from typing import List

from talon import Context, Module, actions

mod = Module()
ctx_zathura = Context()
ctx_zathura.matches = r"""
app: zathura
"""


@ctx_zathura.action_class("user")
class Actions:
    def pop():
        """TODO"""
        actions.key("ctrl-d")
示例#6
0
DEFINED_COMMANDS_KEY = "defined-commands"


module = Module()
module.list(
    "emacs_mode_commands", desc="All currently active major- and minor-mode commands."
)


@module.capture(rule="{user.emacs_mode_commands}")
def emacs_mode_command(m) -> str:
    """An Emacs major- or minor-mode command."""
    return m.emacs_mode_commands


context = Context()


def _extract_mode_commands(all_commands: List[str]) -> List[str]:
    """Extract the major- and minor-mode commands from `all_commands`."""
    mode_commands = {}
    for command in all_commands:
        if command.endswith("-mode"):
            mode_commands[spoken_form(command)] = command
    return mode_commands


def _set_mode_commands(emacs_state: Dict) -> List[str]:
    """Extract & set the current `-mode` commands."""
    defined_commands = emacs_state.get(DEFINED_COMMANDS_KEY, [])
    context.lists["user.emacs_mode_commands"] = _extract_mode_commands(defined_commands)
示例#7
0
from talon import Context

hiss_context = Context()
hiss_context.matches = r"""
tag: user.emacs
# Currently, the way Talon parses contexts means the basic context would
# override hiss-to-cancel too, so we manually exclude it.
user.zoom_mouse_zooming: False
"""

# Scrolling in Emacs is invasive - it doesn't just scroll, it moves the cursor.
# Hisses will misfire while speaking, so we add a deadzone to ignore short
# hisses.
hiss_context.settings["user.hiss_start_deadzone"] = 300
示例#8
0
from talon import Context, Module, actions

# How old a request file needs to be before we declare it stale and are willing
# to remove it
STALE_TIMEOUT_MS = 60_000

# The amount of time to wait for VSCode to perform a command, in seconds
VSCODE_COMMAND_TIMEOUT_SECONDS = 3.0

# When doing exponential back off waiting for vscode to perform a command, how
# long to sleep the first time
MINIMUM_SLEEP_TIME_SECONDS = 0.0005

mod = Module()

ctx = Context()
mac_ctx = Context()

ctx.matches = r"""
app: vscode
"""
mac_ctx.matches = r"""
os: mac
app: vscode
"""


class NotSet:
    def __repr__(self):
        return "<argument not set>"
示例#9
0
from talon import Module, Context, actions, ui, imgui, clip, settings, registry, app

mod = Module()
ctx = Context()

ctx_talon_lists = Context()

# restrict all the talon_* lists to when the user.talon_populate_lists tag
# is active to prevent them from being active in contexts where they are not wanted.
# Do not enable this tag with dragon, as it will be unusable.
# with conformer, the latency increase may also be unacceptable depending on your cpu
# see https://github.com/knausj85/knausj_talon/issues/600
ctx_talon_lists.matches = r"""
tag: user.talon_populate_lists
"""

mod.tag("talon_python", "Tag to activate talon-specific python commands")
mod.tag(
    "talon_populate_lists",
    "Tag to activate talon-specific lists of actions, scopes, modes etcetera. Do not use this tag with dragon"
)
mod.list("talon_actions")
mod.list("talon_lists")
mod.list("talon_captures")
mod.list("talon_apps")
mod.list("talon_tags")
mod.list("talon_modes")
mod.list("talon_settings")
mod.list("talon_scopes")
mod.list("talon_modes")