ideasman42 / nerd-dictation

Simple, hackable offline speech to text - using the VOSK-API.
GNU General Public License v3.0
1.21k stars 104 forks source link

Broken pipe issue #80

Open nPrevail opened 1 year ago

nPrevail commented 1 year ago

This problem has been SOLVED!

https://github.com/ideasman42/nerd-dictation/issues/72#issuecomment-1351741030

-- Original post:

Current specs: Fedora 37/GNOME 43.2 Wayland

I've followed the instructions, I have nerd-dictation directory in ~/home/USER/.config/nerd-dictation

I put the zip contents of the small VOSK model into ~/home/USER/.config/nerd-dictation/model

I installed YDOTOOL v1.0.3 via sudo dnf in ydotool

I did the following to configure YDOTOOL: https://github.com/ideasman42/nerd-dictation/blob/master/readme-ydotool.rst and https://github.com/ReimuNotMoe/ydotool/issues/25#issuecomment-535842993

Rebooted the computer and ran sudo ydotoold

From terminal, while in the nerd-dictation directory, I've ran: python3 nerd-dictation begin --simulate-input-tool=YDOTOOL

I would get the following output:


python3 nerd-dictation begin --simulate-input-tool=YDOTOOL
Traceback (most recent call last):
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 1574, in <module>
    main()
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 1570, in main
    args.func(args)
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 1492, in <lambda>
    func=lambda args: main_begin(
                      ^^^^^^^^^^^
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 1203, in main_begin
    found_any = text_from_vosk_pipe(
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 1006, in text_from_vosk_pipe
    handle_fn_wrapper(text, True)
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 943, in handle_fn_wrapper
    handle_fn(len(text_prev) - match, text_curr[match:])
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 197, in simulate_typing_with_ydotool
    run_command_or_exit_on_failure(
  File "/home/nPrev/.config/nerd-dictation/nerd-dictation", line 50, in run_command_or_exit_on_failure
    subprocess.check_output(cmd)
  File "/usr/lib64/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ydotool', 'type', '--next-delay', '5', '--', 'the']' returned non-zero exit status 2.
write() failed: Broken pipe

Any idea what I'm doing wrong?

goatchurchprime commented 1 year ago

It means that ydotool isn't running. Try calling the tool directly to see any issues

ydotool type --next-delay 5 -- the

I couldn't get that to work. However by putting in the following code (and the appropriate options) I got it to print continuously to the stdout, while applying the backspaces as well.

# -----------------------------------------------------------------------------
# Simulate Input: STDOUT
#
def simulate_typing_with_stout(delete_prev_chars: int, text: str) -> None:
    cmd = "stdout"

    # No setup/tear-down.
    if delete_prev_chars == SIMULATE_INPUT_CODE_COMMAND:
        return

    if delete_prev_chars:
        sys.stdout.write("\x08"*delete_prev_chars)

    sys.stdout.write(text)
    sys.stdout.flush()

Command to run:

nerd-dictation begin --timeout 5 --simulate-input-tool STDOUT