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
All checks were successful
Update Nix Packages with nix-update / nix-update (push) Successful in 2m34s
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
wtype,
|
||||
libnotify,
|
||||
pipewire,
|
||||
procps,
|
||||
busybox,
|
||||
}: let
|
||||
script = writeShellScriptBin "stt-ptt" ''
|
||||
@@ -15,7 +16,6 @@
|
||||
CACHE_DIR="''${XDG_CACHE_HOME:-$HOME/.cache}/stt-ptt"
|
||||
MODEL_DIR="''${XDG_DATA_HOME:-$HOME/.local/share}/stt-ptt/models"
|
||||
AUDIO="$CACHE_DIR/stt.wav"
|
||||
PID_FILE="$CACHE_DIR/stt.pid"
|
||||
|
||||
# Configurable via environment
|
||||
STT_MODEL="''${STT_MODEL:-$MODEL_DIR/ggml-large-v3-turbo.bin}"
|
||||
@@ -26,26 +26,31 @@
|
||||
PW_RECORD="${pipewire}/bin/pw-record"
|
||||
WHISPER="${whisper-cpp}/bin/whisper-cli"
|
||||
WTYPE="${wtype}/bin/wtype"
|
||||
PKILL="${procps}/bin/pkill"
|
||||
MKDIR="${busybox}/bin/mkdir"
|
||||
RM="${busybox}/bin/rm"
|
||||
CAT="${busybox}/bin/cat"
|
||||
KILL="${busybox}/bin/kill"
|
||||
TR="${busybox}/bin/tr"
|
||||
SED="${busybox}/bin/sed"
|
||||
SLEEP="${busybox}/bin/sleep"
|
||||
|
||||
# Ensure cache directory exists
|
||||
"$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
|
||||
start)
|
||||
"$RM" -f "$AUDIO" "$PID_FILE"
|
||||
kill_existing
|
||||
"$RM" -f "$AUDIO"
|
||||
"$NOTIFY" -t "$STT_NOTIFY_TIMEOUT" -a "stt-ptt" "Recording..."
|
||||
"$PW_RECORD" --rate=16000 --channels=1 "$AUDIO" &
|
||||
echo $! > "$PID_FILE"
|
||||
;;
|
||||
stop)
|
||||
[[ -f "$PID_FILE" ]] && "$KILL" "$("$CAT" "$PID_FILE")" 2>/dev/null
|
||||
"$RM" -f "$PID_FILE"
|
||||
kill_existing
|
||||
|
||||
if [[ -f "$AUDIO" ]]; then
|
||||
if [[ ! -f "$STT_MODEL" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user