Skip to content

Instantly share code, notes, and snippets.

@SkymanOne
Created February 11, 2026 15:55
Show Gist options
  • Select an option

  • Save SkymanOne/a4f4ef011359723af0372ba5df6628f7 to your computer and use it in GitHub Desktop.

Select an option

Save SkymanOne/a4f4ef011359723af0372ba5df6628f7 to your computer and use it in GitHub Desktop.
Simple utility to dictate prompt and save it to clipboard for coding agents
#!/usr/bin/env bash
# Dictate: press Enter to start/stop recording, transcribes, pastes into Claude Code.
#
# Run in a separate terminal next to Claude Code.
# Press Enter to start recording, Enter again to stop.
# Transcribed text is copied to clipboard and pasted into the previous window.
#
# Usage:
# dictate # base model
# dictate small # whisper small model
#
# Dependencies:
# brew install sox
# pip install openai-whisper
# or
# brew install openai-whisper
set -euo pipefail
MODEL="${1:-base}"
for cmd in rec whisper; do
if ! command -v "$cmd" &>/dev/null; then
echo "Missing '$cmd'. Install:"
[ "$cmd" = "rec" ] && echo " brew install sox" || echo " pip install openai-whisper"
exit 1
fi
done
while true; do
AUDIO_FILE="/tmp/dictate_$$.wav"
echo ""
read -r -p "Press Enter to record (q to quit)... " INPUT
[[ "$INPUT" == "q" ]] && echo "Bye!" && exit 0
# Start recording in background
rec -q -r 16000 -c 1 -b 16 "$AUDIO_FILE" 2>/dev/null &
REC_PID=$!
echo "πŸŽ™ Recording... press Enter to stop"
read -r
kill "$REC_PID" 2>/dev/null
wait "$REC_PID" 2>/dev/null || true
if [ ! -s "$AUDIO_FILE" ]; then
echo "No audio captured."
rm -f "$AUDIO_FILE"
continue
fi
echo "πŸ“ Transcribing..."
whisper "$AUDIO_FILE" --model "$MODEL" --language en --output_format txt --output_dir /tmp &>/dev/null
TXT_FILE="${AUDIO_FILE%.wav}.txt"
if [ ! -f "$TXT_FILE" ]; then
echo "Transcription failed."
rm -f "$AUDIO_FILE"
continue
fi
TEXT=$(sed 's/^[[:space:]]*//;s/[[:space:]]*$//' "$TXT_FILE")
rm -f "$AUDIO_FILE" "$TXT_FILE"
if [ -z "$TEXT" ]; then
echo "No speech detected."
continue
fi
echo ""
echo "πŸ“‹ $TEXT"
echo ""
echo -n "$TEXT" | pbcopy
echo "(copied to clipboard)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment