Skip to content

Instantly share code, notes, and snippets.

@arunsathiya
Created February 5, 2026 04:56
Show Gist options
  • Select an option

  • Save arunsathiya/cddfc598ac29d3b9e160b3962d08bdff to your computer and use it in GitHub Desktop.

Select an option

Save arunsathiya/cddfc598ac29d3b9e160b3962d08bdff to your computer and use it in GitHub Desktop.
Voxtral API Transcription for macOS - Quick transcription using Mistral's Voxtral API with sox

Voxtral API Transcription for macOS

Quick transcription using Mistral's Voxtral API with sox and Keyboard Maestro (or similar).

Prerequisites

brew install sox

Get a Mistral API key from: https://console.mistral.ai/

Setup

Add to your ~/.secrets or ~/.zshrc:

export MISTRAL_API_KEY="your-api-key-here"

Keyboard Maestro Macros

Start Recording

Trigger: Your preferred hotkey (e.g., F13)

Action: Execute Shell Script

PID_FILE="/tmp/voxtral_recording.pid"; AUDIO_FILE="/tmp/voxtral_audio.wav"; if [ -f "$PID_FILE" ] && ps -p $(cat "$PID_FILE") >/dev/null 2>&1; then exit 0; fi; rm -f "$AUDIO_FILE"; sox -d -t wav -r 16000 -c 1 -b 16 "$AUDIO_FILE" >/dev/null 2>&1 & echo $! > "$PID_FILE"

Stop & Transcribe

Trigger: Same key release (or different hotkey)

Action: Execute Shell Script

PID_FILE="/tmp/voxtral_recording.pid"; AUDIO_FILE="/tmp/voxtral_audio.wav"; API_KEY="${MISTRAL_API_KEY:-}"; if [ -z "$API_KEY" ]; then exit 1; fi; if [ ! -f "$PID_FILE" ] || ! ps -p $(cat "$PID_FILE") >/dev/null 2>&1; then exit 0; fi; kill $(cat "$PID_FILE") 2>/dev/null; rm -f "$PID_FILE"; sleep 0.5; RESPONSE=$(curl -s -X POST https://api.mistral.ai/v1/audio/transcriptions -H "Authorization: Bearer $API_KEY" -F "model=voxtral-mini-2507" -F "file=@$AUDIO_FILE" 2>&1); if [ $? -ne 0 ]; then exit 1; fi; if echo "$RESPONSE" | grep -q '"error"'; then exit 1; fi; TEXT=$(echo "$RESPONSE" | grep -o '"text":"[^"]*"' | cut -d'"' -f4); if [ -z "$TEXT" ]; then exit 1; fi; echo "$TEXT" | pbcopy; osascript -e "tell application \"System Events\" to keystroke \"$TEXT\""; rm -f "$AUDIO_FILE"

How It Works

  1. Start: Records audio using sox at 16kHz mono 16-bit WAV (Voxtral requirement)
  2. Stop: Sends audio to Mistral's Voxtral API, types result at cursor

Troubleshooting

  • "sox not found": Run brew install sox
  • "MISTRAL_API_KEY not set": Add the export to your shell config
  • No transcription: Check your API key is valid at console.mistral.ai

License

MIT - Use at your own risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment