Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro detection #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/default/nerd-dictation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
# -----------------------------------------------------------------------------
# Main Processing Function

def nerd_dictation_macro_process(command):
if command.startswith("command") and command != "command":
return [("xdotool", "click", "--clearmodifiers", "--delay", "10", "1")]
return None

def nerd_dictation_process(text):

for match, replacement in TEXT_REPLACE_REGEX:
Expand Down
36 changes: 32 additions & 4 deletions nerd-dictation
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,22 @@ class from_words_to_digits:
i -= 1
i += 1

# -----------------------------------------------------------------------------
# Process Macro
#

def process_macro_with_user_config(user_config: ModuleType, text: str) -> str:

macro_fn_name = "nerd_dictation_macro_process"
macro_process_fn = getattr(user_config, macro_fn_name)
if macro_process_fn is None:
return None
try:
return macro_process_fn(text)
except Exception as ex:
sys.stderr.write("Failed to run %r with error %s\n" % (user_config, str(ex)))
sys.exit(1)


# -----------------------------------------------------------------------------
# Process Text
Expand Down Expand Up @@ -595,10 +611,19 @@ def text_from_vosk_pipe(

# Progressive support (type as you speak).
nonlocal text_prev
if progressive_continuous:
text_curr = process_fn(text)
else:
text_curr = process_fn(" ".join(text_list + [text]))

user_config = user_config_as_module_or_none()
if user_config is not None:
macro = process_macro_with_user_config(user_config, text)
if macro is not None:
text_curr = ""
text_list = []

if macro is None:
if progressive_continuous:
text_curr = process_fn(text)
else:
text_curr = process_fn(" ".join(text_list + [text]))

if text_curr != text_prev:
match = min(len(text_curr), len(text_prev))
Expand All @@ -613,6 +638,9 @@ def text_from_vosk_pipe(
text_prev = text_curr

if not is_partial_arg:
if macro is not None:
for command in macro:
subprocess.check_output(command).decode("utf-8")
if progressive_continuous:
text_prev = ""
else:
Expand Down