This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / mic-to-text / mic-to-text.sh
1.3 kB 42 lines
1#!/usr/bin/env bash 2set -euo pipefail 3 4# Default recording duration in seconds 5DURATION=${1:-5} 6 7# Model cache directory 8MODEL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/whisper-models" 9mkdir -p "$MODEL_DIR" 10 11# Default model 12MODEL_NAME="${WHISPER_MODEL:-base.en}" 13MODEL_FILE="$MODEL_DIR/ggml-$MODEL_NAME.bin" 14 15# Download model if not present 16if [ ! -f "$MODEL_FILE" ]; then 17 echo "Downloading $MODEL_NAME model (first run only)..." >&2 18 MODEL_URL="https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-$MODEL_NAME.bin" 19 curl -L -o "$MODEL_FILE.tmp" "$MODEL_URL" && mv "$MODEL_FILE.tmp" "$MODEL_FILE" 20fi 21 22# Temporary file for audio recording 23TEMP_AUDIO=$(mktemp /tmp/mic-to-text-XXXXXX.wav) 24trap 'rm -f "$TEMP_AUDIO"' EXIT 25 26echo "Recording for $DURATION seconds... (press Ctrl+C to stop early)" >&2 27 28# Record audio from default microphone 29# -r 16000: sample rate 16kHz (optimal for speech recognition) 30# -c 1: mono channel 31# -b 16: 16-bit audio 32rec -q -r 16000 -c 1 -b 16 "$TEMP_AUDIO" trim 0 "$DURATION" || true 33 34if [ ! -s "$TEMP_AUDIO" ]; then 35 echo "Error: No audio recorded" >&2 36 exit 1 37fi 38 39echo "Transcribing locally..." >&2 40 41# Transcribe using whisper.cpp (runs locally, no API calls) 42whisper-cli -m "$MODEL_FILE" -f "$TEMP_AUDIO" -np