cancel
The community/plugin/cancel
directory contains files that implement the ability to cancel a spoken command using a specific phrase.
The core logic is implemented in cancel.py. This file defines an action cancel_current_phrase()
which sets a global timestamp. It also sets a pre:phrase
handler, which is called before each command phrase is executed. This handler checks if a spoken phrase:
- Started before Talon woke up. This is to prevent accidental commands from being executed if Talon is activated with a non-speech sound or a key press.
- Ends with the cancel phrase defined as
"cancel cancel"
.
If either of these conditions is true, then the phrase is canceled.
The cancel.talon file defines the grammar to invoke the cancel functionality. It defines two commands:
cancel cancel$: skip()
: This maps the spoken phrase "cancel cancel" to askip()
action. In the context of Talon, this action consumes the spoken phrase, preventing it from being executed as a command. The actual logic for canceling a phrase based on this is incancel.py
ignore [<phrase>]$: app.notify("Command ignored")
: This allows you to say "ignore" followed by any phrase and it will notify the user of the ignored command. It's designed for situations where you want to say something aloud to a human but don't want Talon to interpret it as a command.