speak-selection v2 + hermenux home
This commit is contained in:
1 parent
12fe9c4603
commit
c63a3e34e9
4 files changed
+69
-13
No files matched your search
@@ -51,7 +51,7 @@ split under `conf/` and pulled in with `require()`.
|
|||||||
hypr/
|
hypr/
|
||||||
├── hyprland.lua # entry point; require()s conf/*.lua in order
|
├── hyprland.lua # entry point; require()s conf/*.lua in order
|
||||||
├── screen-record.sh # wf-recorder toggle (bound to Mod+R)
|
├── 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
|
├── speak-selection.nu # piper TTS of primary selection (bound to Mod+M); press again to stop; --cache reuses audio
|
||||||
├── xdph.conf # xdph screencopy workaround (force_shm); hyprlang, read by xdph itself
|
├── xdph.conf # xdph screencopy workaround (force_shm); hyprlang, read by xdph itself
|
||||||
├── .luarc.json # lua-language-server config (library = ../../hypr-types)
|
├── .luarc.json # lua-language-server config (library = ../../hypr-types)
|
||||||
├── dms/ # DMS-auto-generated Hyprland overrides (colors/layout/windowrules);
|
├── dms/ # DMS-auto-generated Hyprland overrides (colors/layout/windowrules);
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env nu
|
#!/usr/bin/env nu
|
||||||
|
|
||||||
|
let piperFolder = $env.HOME | path join ".local/share/piper"
|
||||||
|
let piperSoundCacheFolder = $env.HOME | path join ".local/share/piper-cache"
|
||||||
|
let modelName = "en_US-hfc_female-medium"
|
||||||
|
|
||||||
def pidfile [] {
|
def pidfile [] {
|
||||||
$"($env.XDG_RUNTIME_DIR? | default "/tmp")/hypr-speak.pid"
|
$"($env.XDG_RUNTIME_DIR? | default "/tmp")/hypr-speak.pid"
|
||||||
}
|
}
|
||||||
@@ -21,20 +25,44 @@ def kill-tree [pid: int] {
|
|||||||
let _ = (^kill -KILL $pid | complete)
|
let _ = (^kill -KILL $pid | complete)
|
||||||
}
|
}
|
||||||
|
|
||||||
def main [] {
|
def terminate-last [file: string] {
|
||||||
let file = (pidfile)
|
|
||||||
|
|
||||||
if ($file | path exists) {
|
if ($file | path exists) {
|
||||||
let old = (try { open --raw $file | str trim | into int } catch { null })
|
let old = (try { open --raw $file | str trim | into int } catch { null })
|
||||||
rm --force $file
|
rm --force $file
|
||||||
if $old != null and (pid-alive $old) {
|
if $old != null and (pid-alive $old) {
|
||||||
kill-tree $old
|
kill-tree $old
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show a failure notification. Works with `complete` results
|
||||||
|
# ({exit_code, stderr, ...}) and `catch` error records.
|
||||||
|
def notify-error [context: string, err: record] {
|
||||||
|
let exit = ($err | get -o exit_code)
|
||||||
|
let detail = if $exit != null {
|
||||||
|
let stderr = ($err | get -o stderr | default "")
|
||||||
|
if ($stderr | is-empty) { $"exit ($exit)" } else { $"exit ($exit): ($stderr | str trim | lines | last)" }
|
||||||
|
} else {
|
||||||
|
$err.msg
|
||||||
|
}
|
||||||
|
let reply = notify-send -i dialog-error -A Yes="Copy to Clipboard" $"piper failed ($context)" $detail
|
||||||
|
if $reply == "Yes" {
|
||||||
|
($err | get -o stderr | default "") | ^xclip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def main [--cache] {
|
||||||
|
let file = (pidfile)
|
||||||
|
if (terminate-last $file) {
|
||||||
|
notify-send -i dialog-information "Piper" "Stopped"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let paste = (^wl-paste --primary | complete)
|
let paste = (^wl-paste --primary | complete)
|
||||||
if $paste.exit_code != 0 {
|
if $paste.exit_code != 0 {
|
||||||
|
notify-send -i dialog-warning "Piper" "No text, make sure to copy something to clipboard"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,12 +73,42 @@ def main [] {
|
|||||||
| str trim)
|
| str trim)
|
||||||
|
|
||||||
if ($text | is-empty) {
|
if ($text | is-empty) {
|
||||||
|
notify-send -i dialog-warning "Piper" "No text, make sure to copy something to clipboard"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# cache key includes the model so different voices don't collide
|
||||||
|
let text_sha = ($"($modelName)|($text)" | hash sha256)
|
||||||
|
let cache_file = $piperSoundCacheFolder | path join $"($text_sha).wav"
|
||||||
|
|
||||||
$"($nu.pid)" | save --force $file
|
$"($nu.pid)" | save --force $file
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$text | ^piper -m en_US-hfc_female-medium
|
notify-send -i dialog-information $"Piper `($modelName)`" $"Text: ($text)"
|
||||||
|
|
||||||
|
# skip piper when the audio is already cached
|
||||||
|
if not ($cache and ($cache_file | path exists)) {
|
||||||
|
^mkdir -p $piperSoundCacheFolder
|
||||||
|
let res = ($text | ^piper -m $modelName --data-dir $piperFolder --output-file $cache_file | complete)
|
||||||
|
if $res.exit_code != 0 {
|
||||||
|
notify-error "piper" $res
|
||||||
|
rm --force $cache_file
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = (^ffplay -nodisp -autoexit $cache_file | complete)
|
||||||
|
if $res.exit_code != 0 {
|
||||||
|
notify-error "ffplay" $res
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch { |err|
|
||||||
|
notify-error "unexpected" $err
|
||||||
}
|
}
|
||||||
rm --force $file
|
rm --force $file
|
||||||
|
|
||||||
|
# no caching → don't leave the audio file behind
|
||||||
|
if not $cache {
|
||||||
|
rm --force $cache_file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Generated
+4
-4
@@ -1039,11 +1039,11 @@
|
|||||||
"treefmt-nix": "treefmt-nix_2"
|
"treefmt-nix": "treefmt-nix_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1789680476,
|
"lastModified": 1789749213,
|
||||||
"narHash": "sha256-UOBb4V5OxAKOpgB6N8lRnbtkTRrwTaVzmvcxfmwyisI=",
|
"narHash": "sha256-bYj5LouChA0lYv8c0L06EmT+nNiOwzhWYSAkROBTxSA=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "a538f70bf7cc3d0535f1d5996eb8d807b988621e",
|
"rev": "c8ff8b1f25345e6437c33a708927e430da37dba3",
|
||||||
"revCount": 36,
|
"revCount": 37,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
|
"url": "ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-3
@@ -173,8 +173,6 @@ in
|
|||||||
# bluetooth
|
# bluetooth
|
||||||
blueman
|
blueman
|
||||||
|
|
||||||
# my apps
|
|
||||||
hermenix
|
|
||||||
]);
|
]);
|
||||||
services.usbmuxd.enable = true;
|
services.usbmuxd.enable = true;
|
||||||
# Steam
|
# Steam
|
||||||
@@ -243,7 +241,7 @@ in
|
|||||||
network.externalInterface = "enp191s0";
|
network.externalInterface = "enp191s0";
|
||||||
vcpu = 8;
|
vcpu = 8;
|
||||||
mem = 16384;
|
mem = 16384;
|
||||||
hermesHome = "/var/lib/hermes";
|
hermesHome = "/var/lib/hermes/.hermes";
|
||||||
hostCache.port = ports.hermesCache; # 5000 collides with libretranslate
|
hostCache.port = ports.hermesCache; # 5000 collides with libretranslate
|
||||||
hostAccess = [
|
hostAccess = [
|
||||||
{ port = ports.ollama; }
|
{ port = ports.ollama; }
|
||||||
|
|||||||
Reference in new issue
Block a user