This repository has no description
856 B
28 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Default recording duration in seconds
5DURATION=${1:-5}
6
7# Temporary file for audio recording
8TEMP_AUDIO=$(mktemp /tmp/mic-to-text-XXXXXX.wav)
9trap 'rm -f "$TEMP_AUDIO"' EXIT
10
11echo "Recording for $DURATION seconds... (press Ctrl+C to stop early)" >&2
12
13# Record audio from default microphone
14# -r 16000: sample rate 16kHz (optimal for speech recognition)
15# -c 1: mono channel
16# -b 16: 16-bit audio
17rec -q -r 16000 -c 1 -b 16 "$TEMP_AUDIO" trim 0 "$DURATION" || true
18
19if [ ! -s "$TEMP_AUDIO" ]; then
20 echo "Error: No audio recorded" >&2
21 exit 1
22fi
23
24echo "Transcribing locally..." >&2
25
26# Transcribe using whisper.cpp (runs locally, no API calls)
27# Uses the base model by default, you can override with WHISPER_MODEL env var
28whisper-cpp -m "${WHISPER_MODEL:-base.en}" -f "$TEMP_AUDIO" --no-timestamps --output-txt