-
-
Save rcd27/3cc2238ed56b6eac8e71c5fdede334f3 to your computer and use it in GitHub Desktop.
the-only-working-whisper-typer-ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Voice dictation: run once to start recording, run again to stop + transcribe. | |
| # Text goes to clipboard β paste with Ctrl+V wherever you want. | |
| # Usage: bind to a hotkey in system settings | |
| PID_FILE="/tmp/dictate.pid" | |
| AUDIO_FILE="/tmp/dictate.wav" | |
| API_KEY="$(cat ~/.config/openai-api-key 2>/dev/null)" | |
| PROXY="http://localhost:8888" | |
| if [ -f "$PID_FILE" ]; then | |
| # Stop recording | |
| kill "$(cat "$PID_FILE")" 2>/dev/null | |
| rm -f "$PID_FILE" | |
| notify-send -t 1000 "π€" "Transcribing..." | |
| # Send to OpenAI Whisper API | |
| RESULT=$(curl -s --proxy "$PROXY" \ | |
| -H "Authorization: Bearer $API_KEY" \ | |
| -F "file=@${AUDIO_FILE}" \ | |
| -F "model=whisper-1" \ | |
| -F "language=ru" \ | |
| "https://api.openai.com/v1/audio/transcriptions" | jq -r '.text // empty') | |
| rm -f "$AUDIO_FILE" | |
| if [ -n "$RESULT" ]; then | |
| echo -n "$RESULT" | nohup xclip -selection clipboard &>/dev/null & | |
| notify-send -t 2000 "π€ Ctrl+V to paste" "$RESULT" | |
| else | |
| notify-send -t 2000 "π€" "Nothing recognized" | |
| fi | |
| else | |
| # Start recording | |
| parecord --format=s16le --rate=16000 --channels=1 "$AUDIO_FILE" & | |
| echo $! > "$PID_FILE" | |
| notify-send -t 1000 "π€" "Recording..." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment