fix: stt-ptt use pkill for better process management
All checks were successful
Update Nix Packages with nix-update / nix-update (push) Successful in 2m34s

This commit is contained in:
m3tm3re
2026-01-26 05:16:29 +01:00
parent 932dffce51
commit 308a60888b

View File

@@ -6,6 +6,7 @@
wtype, wtype,
libnotify, libnotify,
pipewire, pipewire,
procps,
busybox, busybox,
}: let }: let
script = writeShellScriptBin "stt-ptt" '' script = writeShellScriptBin "stt-ptt" ''
@@ -15,7 +16,6 @@
CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}/stt-ptt" CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}/stt-ptt"
MODEL_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/stt-ptt/models" MODEL_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/stt-ptt/models"
AUDIO="$CACHE_DIR/stt.wav" AUDIO="$CACHE_DIR/stt.wav"
PID_FILE="$CACHE_DIR/stt.pid"
# Configurable via environment # Configurable via environment
STT_MODEL="''${STT_MODEL:-$MODEL_DIR/ggml-large-v3-turbo.bin}" STT_MODEL="''${STT_MODEL:-$MODEL_DIR/ggml-large-v3-turbo.bin}"
@@ -26,26 +26,31 @@
PW_RECORD="${pipewire}/bin/pw-record" PW_RECORD="${pipewire}/bin/pw-record"
WHISPER="${whisper-cpp}/bin/whisper-cli" WHISPER="${whisper-cpp}/bin/whisper-cli"
WTYPE="${wtype}/bin/wtype" WTYPE="${wtype}/bin/wtype"
PKILL="${procps}/bin/pkill"
MKDIR="${busybox}/bin/mkdir" MKDIR="${busybox}/bin/mkdir"
RM="${busybox}/bin/rm" RM="${busybox}/bin/rm"
CAT="${busybox}/bin/cat"
KILL="${busybox}/bin/kill"
TR="${busybox}/bin/tr" TR="${busybox}/bin/tr"
SED="${busybox}/bin/sed" SED="${busybox}/bin/sed"
SLEEP="${busybox}/bin/sleep"
# Ensure cache directory exists # Ensure cache directory exists
"$MKDIR" -p "$CACHE_DIR" "$MKDIR" -p "$CACHE_DIR"
# Kill any existing pw-record for this audio file (prevents orphan nodes)
kill_existing() {
"$PKILL" -f "pw-record.*$AUDIO" 2>/dev/null
"$SLEEP" 0.1
}
case "''${1:-}" in case "''${1:-}" in
start) start)
"$RM" -f "$AUDIO" "$PID_FILE" kill_existing
"$RM" -f "$AUDIO"
"$NOTIFY" -t "$STT_NOTIFY_TIMEOUT" -a "stt-ptt" "Recording..." "$NOTIFY" -t "$STT_NOTIFY_TIMEOUT" -a "stt-ptt" "Recording..."
"$PW_RECORD" --rate=16000 --channels=1 "$AUDIO" & "$PW_RECORD" --rate=16000 --channels=1 "$AUDIO" &
echo $! > "$PID_FILE"
;; ;;
stop) stop)
[[ -f "$PID_FILE" ]] && "$KILL" "$("$CAT" "$PID_FILE")" 2>/dev/null kill_existing
"$RM" -f "$PID_FILE"
if [[ -f "$AUDIO" ]]; then if [[ -f "$AUDIO" ]]; then
if [[ ! -f "$STT_MODEL" ]]; then if [[ ! -f "$STT_MODEL" ]]; then