misc: formatting + updates that weren't commited properly before

This commit is contained in:
Pierre Martin
2025-11-27 17:16:07 +01:00
parent 2dc7c688ed
commit 1da4bf6163
12 changed files with 400 additions and 295 deletions

9
files/curl-timings.txt Normal file
View File

@@ -0,0 +1,9 @@
time_namelookup: %{time_namelookup}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_redirect: %{time_redirect}s\n
time_starttransfer: %{time_starttransfer}s\n
----------\n
time_total: %{time_total}s\n
Legend: https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2EfInkqn7sNtWkWFdxPDk4/2f3e1c0202ed6025bbe12f6f540c1b4a/Screen-Shot-2018-10-16-at-14.51.29-1.png

View File

@@ -27,85 +27,85 @@ MODEL="${STT_MODEL:-small}"
# Notification helper (silently fails if no daemon)
notify() {
notify-send "STT" "$1" -t "${2:-2000}" 2>/dev/null || echo "[STT] $1"
notify-send "STT" "$1" -t "${2:-2000}" 2>/dev/null || echo "[STT] $1"
}
# Telecharge le modele si absent
download_model() {
local model_file="${MODEL_DIR}/ggml-${MODEL}.bin"
if [[ ! -f "$model_file" ]]; then
mkdir -p "$MODEL_DIR"
notify "Telechargement du modele ${MODEL}..." 5000
local url="https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${MODEL}.bin"
curl -L "$url" -o "$model_file"
notify "Modele ${MODEL} pret"
fi
local model_file="${MODEL_DIR}/ggml-${MODEL}.bin"
if [[ ! -f "$model_file" ]]; then
mkdir -p "$MODEL_DIR"
notify "Telechargement du modele ${MODEL}..." 5000
local url="https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${MODEL}.bin"
curl -L "$url" -o "$model_file"
notify "Modele ${MODEL} pret"
fi
}
start_recording() {
# Ne pas démarrer si déjà en cours
if [[ -f "$RECORDING_PID" ]] && kill -0 "$(cat "$RECORDING_PID")" 2>/dev/null; then
return 0
fi
download_model
# Enregistre avec arecord (format compatible whisper.cpp)
arecord -f S16_LE -r 16000 -c 1 -t wav "$AUDIO_FILE" &
echo $! > "$RECORDING_PID"
notify "Enregistrement..." 1000
# Ne pas démarrer si déjà en cours
if [[ -f "$RECORDING_PID" ]] && kill -0 "$(cat "$RECORDING_PID")" 2>/dev/null; then
return 0
fi
download_model
# Enregistre avec arecord (format compatible whisper.cpp)
arecord -f S16_LE -r 16000 -c 1 -t wav "$AUDIO_FILE" &
echo $! >"$RECORDING_PID"
notify "Enregistrement..." 1000
}
stop_and_transcribe() {
if [[ -f "$RECORDING_PID" ]]; then
kill "$(cat "$RECORDING_PID")" 2>/dev/null || true
rm -f "$RECORDING_PID"
sleep 0.3 # laisse arecord finaliser le fichier
if [[ -f "$RECORDING_PID" ]]; then
kill "$(cat "$RECORDING_PID")" 2>/dev/null || true
rm -f "$RECORDING_PID"
sleep 0.3 # laisse arecord finaliser le fichier
if [[ ! -f "$AUDIO_FILE" ]] || [[ ! -s "$AUDIO_FILE" ]]; then
notify "Pas d'audio enregistre"
rm -f "$AUDIO_FILE"
return 1
fi
notify "Transcription..." 1000
local model_file="${MODEL_DIR}/ggml-${MODEL}.bin"
# Transcription avec whisper.cpp
TEXT=$(whisper-cli \
-m "$model_file" \
-l fr \
-nt \
-np \
"$AUDIO_FILE" 2>&1 \
| grep -v "^load_backend:" \
| tr -d '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
rm -f "$AUDIO_FILE"
# Tape le texte au curseur
if [[ -n "$TEXT" ]]; then
sleep 0.1 # petit delai pour focus
xdotool type --delay 10 -- "$TEXT"
notify "$TEXT"
else
notify "Aucun texte detecte"
fi
if [[ ! -f "$AUDIO_FILE" ]] || [[ ! -s "$AUDIO_FILE" ]]; then
notify "Pas d'audio enregistre"
rm -f "$AUDIO_FILE"
return 1
fi
notify "Transcription..." 1000
local model_file="${MODEL_DIR}/ggml-${MODEL}.bin"
# Transcription avec whisper.cpp
TEXT=$(whisper-cli \
-m "$model_file" \
-l fr \
-nt \
-np \
"$AUDIO_FILE" 2>&1 |
grep -v "^load_backend:" |
tr -d '\n' |
sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
rm -f "$AUDIO_FILE"
# Tape le texte au curseur
if [[ -n "$TEXT" ]]; then
sleep 0.1 # petit delai pour focus
xdotool type --delay 10 -- "$TEXT"
notify "$TEXT"
else
notify "Aucun texte detecte"
fi
fi
}
case "${1:-toggle}" in
start) start_recording ;;
stop) stop_and_transcribe ;;
toggle)
if [[ -f "$RECORDING_PID" ]]; then
stop_and_transcribe
else
start_recording
fi
;;
*)
echo "Usage: $0 {start|stop|toggle}"
exit 1
;;
start) start_recording ;;
stop) stop_and_transcribe ;;
toggle)
if [[ -f "$RECORDING_PID" ]]; then
stop_and_transcribe
else
start_recording
fi
;;
*)
echo "Usage: $0 {start|stop|toggle}"
exit 1
;;
esac