Skip to content

Instantly share code, notes, and snippets.

@kwappa
Created March 19, 2026 05:03
Show Gist options
  • Select an option

  • Save kwappa/faa68dbdeee3cd81b2224422d74d00b8 to your computer and use it in GitHub Desktop.

Select an option

Save kwappa/faa68dbdeee3cd81b2224422d74d00b8 to your computer and use it in GitHub Desktop.
whisper-cppによる文字起こしスクリプト
#!/bin/bash
set -euo pipefail
WHISPER_MODELS="${WHISPER_MODELS:-/Volumes/YourDrive/whisper-models}"
usage() {
cat <<EOF
Usage: $(basename "$0") [-l lang] [-m model] <input_file>
Options:
-l lang Language code (default: ja)
-m model Model name: tiny, base, small, medium, large-v3, etc. (default: medium)
Environment:
WHISPER_MODELS Directory containing ggml model files
(default: /Volumes/YourDrive/whisper-models)
Examples:
$(basename "$0") recording.m4a
$(basename "$0") -l en -m large-v3 meeting.mp4
EOF
exit 1
}
lang="ja"
model="medium"
while getopts "l:m:h" opt; do
case "$opt" in
l) lang="$OPTARG" ;;
m) model="$OPTARG" ;;
h) usage ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
[[ $# -lt 1 ]] && usage
input="$1"
model_file="${WHISPER_MODELS}/ggml-${model}.bin"
if [[ ! -f "$input" ]]; then
echo "Error: input file not found: $input" >&2
exit 1
fi
if [[ ! -f "$model_file" ]]; then
echo "Error: model file not found: $model_file" >&2
echo "Run: whisper-cpp-download-ggml-model $model $WHISPER_MODELS" >&2
exit 1
fi
for cmd in ffmpeg whisper-cli; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is not installed" >&2
exit 1
fi
done
timestamp=$(date +%Y%m%d_%H%M%S)
random_suffix=$((RANDOM % 10000))
wav_tmp="/tmp/whisper-${timestamp}-${random_suffix}.wav"
cleanup() {
rm -f "$wav_tmp"
}
trap cleanup EXIT
ffmpeg -i "$input" -ar 16000 -ac 1 -c:a pcm_s16le "$wav_tmp" -y -loglevel error
whisper-cli -m "$model_file" -l "$lang" -f "$wav_tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment