#!/bin/bash # record_and_transcribe.sh # Gracefully records audio from macOS mic and runs MLX Canary transcription. VENV_PYTHON="/Users/santosh/Desktop/ASR-Playground/.venv/bin/python" GEN_SCRIPT="/Users/santosh/Desktop/ASR-Playground/mlx_canary/generate.py" WAV_OUT="/Users/santosh/Desktop/ASR-Playground/mlx_canary/recording.wav" # Ensure we use correct path relative to script directory DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" GEN_SCRIPT="$DIR/generate.py" WAV_OUT="$DIR/recording.wav" echo "==================================================" echo " Canary-Qwen-2.5B: Record & Transcribe " echo "==================================================" echo "" echo "Press [ENTER] to start recording from your microphone..." read -r # Find ffmpeg binary FFMPEG_BIN="ffmpeg" if ! command -v ffmpeg &> /dev/null; then if [ -f "/opt/homebrew/bin/ffmpeg" ]; then FFMPEG_BIN="/opt/homebrew/bin/ffmpeg" elif [ -f "/usr/local/bin/ffmpeg" ]; then FFMPEG_BIN="/usr/local/bin/ffmpeg" else echo "ERROR: 'ffmpeg' was not found on your system." echo "To record audio directly from your terminal, please install ffmpeg via Homebrew:" echo " brew install ffmpeg" echo "" echo "Alternative: You can record your audio using Voice Memos or QuickTime," echo "save it, and run the MLX script directly:" echo " $VENV_PYTHON $GEN_SCRIPT /path/to/your/audio.m4a" exit 1 fi fi # Start ffmpeg in the background. # ":0" or "default" selects the default macOS audio input. $FFMPEG_BIN -y -f avfoundation -i ":0" -ar 16000 -ac 1 "$WAV_OUT" > /dev/null 2>&1 & FFMPEG_PID=$! echo "Recording started. Press [ENTER] to stop recording..." read -r # Stop ffmpeg gracefully (SIGINT allows it to finalize the WAV header) kill -INT "$FFMPEG_PID" wait "$FFMPEG_PID" 2>/dev/null echo "Recording stopped. Saved to: $WAV_OUT" echo "Running MLX transcription..." echo "--------------------------------------------------" # Run inference "$VENV_PYTHON" "$GEN_SCRIPT" "$WAV_OUT" echo "--------------------------------------------------"