From 34cbfb91370e8d4d37ff8b837a4410096b5002d8 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 15 Sep 2026 12:16:40 -0400 Subject: [PATCH] tts keybindings --- configs/fwbook/hypr/ABOUTME.md | 2 + configs/fwbook/hypr/conf/keybindings.lua | 2 +- configs/fwbook/hypr/speak-selection.nu | 56 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 configs/fwbook/hypr/speak-selection.nu diff --git a/configs/fwbook/hypr/ABOUTME.md b/configs/fwbook/hypr/ABOUTME.md index b456970..77f25ee 100644 --- a/configs/fwbook/hypr/ABOUTME.md +++ b/configs/fwbook/hypr/ABOUTME.md @@ -51,6 +51,7 @@ split under `conf/` and pulled in with `require()`. hypr/ ├── hyprland.lua # entry point; require()s conf/*.lua in order ├── screen-record.sh # wf-recorder toggle (bound to Mod+R) +├── speak-selection.nu # piper TTS of primary selection (bound to Mod+M); press again to stop ├── xdph.conf # xdph screencopy workaround (force_shm); hyprlang, read by xdph itself ├── .luarc.json # lua-language-server config (library = ../../hypr-types) ├── dms/ # DMS-auto-generated Hyprland overrides (colors/layout/windowrules); @@ -83,6 +84,7 @@ hypr/ ## Touchpad gestures (niri parity) niri's 3-finger swipes are mirrored in `conf/inputs.lua`: + - **Horizontal** → `scroll_move` (scroll through columns along the tape) - **Vertical** → `workspace` (switch workspaces up/down) - **Mod + swipe (any direction)** → move the whole workspace to the monitor in diff --git a/configs/fwbook/hypr/conf/keybindings.lua b/configs/fwbook/hypr/conf/keybindings.lua index a1f0612..43abc32 100644 --- a/configs/fwbook/hypr/conf/keybindings.lua +++ b/configs/fwbook/hypr/conf/keybindings.lua @@ -147,4 +147,4 @@ hl.bind("XF86AudioMute", hl.dsp.exec_cmd("noctalia msg volume-mute"), { locked = hl.bind("XF86MonBrightnessUp", hl.dsp.exec_cmd("noctalia msg brightness-up"), { locked = true }) hl.bind("XF86MonBrightnessDown", hl.dsp.exec_cmd("noctalia msg brightness-down"), { locked = true }) -hl.bind(mod .. " + M", hl.dsp.exec_cmd("wl-paste --primary | piper -m en_US-hfc_female-medium")) +hl.bind(mod .. " + M", hl.dsp.exec_cmd("nu ~/.config/hypr/speak-selection.nu")) diff --git a/configs/fwbook/hypr/speak-selection.nu b/configs/fwbook/hypr/speak-selection.nu new file mode 100755 index 0000000..6954816 --- /dev/null +++ b/configs/fwbook/hypr/speak-selection.nu @@ -0,0 +1,56 @@ +#!/usr/bin/env nu + +def pidfile [] { + $"($env.XDG_RUNTIME_DIR? | default "/tmp")/hypr-speak.pid" +} + +def pid-alive [pid: int] { + (^kill -0 $pid | complete).exit_code == 0 +} + +def kill-tree [pid: int] { + let kids = (^pgrep -P $pid | complete) + if $kids.exit_code == 0 { + for kid in ($kids.stdout | lines) { + let kid = ($kid | str trim) + if not ($kid | is-empty) { + kill-tree ($kid | into int) + } + } + } + let _ = (^kill -KILL $pid | complete) +} + +def main [] { + let file = (pidfile) + + if ($file | path exists) { + let old = (try { open --raw $file | str trim | into int } catch { null }) + rm --force $file + if $old != null and (pid-alive $old) { + kill-tree $old + return + } + } + + let paste = (^wl-paste --primary | complete) + if $paste.exit_code != 0 { + return + } + + let text = ($paste.stdout + | str replace --all --regex '[\n\t]' ' ' + | str replace --all --regex "[^0-9A-Za-z .,!?'-]" '' + | str replace --all --regex ' +' ' ' + | str trim) + + if ($text | is-empty) { + return + } + + $"($nu.pid)" | save --force $file + try { + $text | ^piper -m en_US-hfc_female-medium + } + rm --force $file +}