diff options
| author | benj <benj@rse8.com> | 2026-05-12 16:42:47 +0800 |
|---|---|---|
| committer | benj <benj@rse8.com> | 2026-05-12 16:42:47 +0800 |
| commit | 5e9ff5b438e7b3001324b9345c3c311a08bf99c4 (patch) | |
| tree | 58f5d7e8bf956d09edaffd17dcfe8ee8b10eddf7 | |
| parent | 81653059a0110d160146742696089fe6a837b171 (diff) | |
| download | mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar.gz mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar.bz2 mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar.lz mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar.xz mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.tar.zst mycfg-5e9ff5b438e7b3001324b9345c3c311a08bf99c4.zip | |
add dictation scripts: vosk live + whisper batch
Diffstat (limited to '')
| -rw-r--r-- | des/i3/config | 5 | ||||
| -rwxr-xr-x | scripts/dictate-toggle.sh | 21 | ||||
| -rwxr-xr-x | scripts/ow-dictate.sh | 50 |
3 files changed, 76 insertions, 0 deletions
diff --git a/des/i3/config b/des/i3/config index 56d9bab..c362382 100644 --- a/des/i3/config +++ b/des/i3/config @@ -39,6 +39,11 @@ bindsym $mod+F8 exec --no-startup-id feh --bg-fill --randomize ~/.mycfg/des/i3/a # Toggle VPN or Proxy bindsym $mod+F4 exec --no-startup-id ~/.mycfg/scripts/toggle-xray.sh +# Live dictation (VOSK via nerd-dictation) — streams into focused field +bindsym $mod+grave exec --no-startup-id ~/.mycfg/scripts/dictate-toggle.sh +# Batch dictation (OpenAI Whisper) — record, then transcribe and type +bindsym $mod+Shift+grave exec --no-startup-id ~/.mycfg/scripts/ow-dictate.sh + # Compositor exec --no-startup-id compton --config ~/.config/compton.conf -b diff --git a/scripts/dictate-toggle.sh b/scripts/dictate-toggle.sh new file mode 100755 index 0000000..d5248ab --- /dev/null +++ b/scripts/dictate-toggle.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Toggle nerd-dictation (VOSK live dictation, types into focused window). +VENV_PY=~/.virtualenvs/dictate/bin/python +ND=~/.local/share/nerd-dictation/nerd-dictation +NOTIFFILE="/tmp/vosk-dictate.notif_id" + +if pgrep -f "nerd-dictation begin" >/dev/null; then + "$VENV_PY" "$ND" end + NID="" + [ -f "$NOTIFFILE" ] && NID=$(cat "$NOTIFFILE") + if [ -n "$NID" ]; then + notify-send -r "$NID" -t 1000 "Dictation" "Stopped" + else + notify-send -t 1000 "Dictation" "Stopped" + fi + rm -f "$NOTIFFILE" +else + NID=$(notify-send -p -t 0 -u low "Dictation" "Listening...") + echo "$NID" > "$NOTIFFILE" + "$VENV_PY" "$ND" begin --full-sentence & +fi diff --git a/scripts/ow-dictate.sh b/scripts/ow-dictate.sh new file mode 100755 index 0000000..db7e9e4 --- /dev/null +++ b/scripts/ow-dictate.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# ~/.mycfg/scripts/ow-dictate.sh — OpenAI Whisper API version + +PIDFILE="/tmp/dictate.pid" +AUDIO="/tmp/dictate.wav" +NOTIFFILE="/tmp/dictate.notif_id" + +NID="" +[ -f "$NOTIFFILE" ] && NID=$(cat "$NOTIFFILE") +notify() { + local args=() + [ -n "$NID" ] && args+=(-r "$NID") + NID=$(notify-send -p "${args[@]}" "$@") + echo "$NID" > "$NOTIFFILE" +} + +if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then + # ── STOP recording, send to API, type ── + kill "$(cat "$PIDFILE")" + rm "$PIDFILE" + + notify -t 2000 "Dictation" "Sending to OpenAI..." + + API_KEY=$(pass show openai.com/api.openai.com/apikey) + + RESPONSE=$(curl -s https://api.openai.com/v1/audio/transcriptions \ + -H "Authorization: Bearer $API_KEY" \ + -F "file=@$AUDIO" \ + -F "model=whisper-1" \ + -F "language=en" \ + -F "response_format=json") + + TEXT=$(echo "$RESPONSE" | jq -r '.text // empty') + + if [ -n "$TEXT" ]; then + xdotool type --clearmodifiers -- "$TEXT" + notify -t 1000 "Dictation" "Done" + else + ERROR=$(echo "$RESPONSE" | jq -r '.error.message // "Unknown error"') + notify -t 3000 "Dictation" "Failed: $ERROR" + fi + + rm -f "$AUDIO" +else + # ── START recording ── + notify -t 0 -u low "Dictation" "Recording..." + + arecord -f S16_LE -r 16000 -c 1 -t wav "$AUDIO" & + echo $! > "$PIDFILE" +fi |
