anibon-local-transcription について
字幕や自動キャプションのない YouTube 動画向けに、音声抽出と whisper.cpp によるローカル文字起こしを案内するスキルです。形式変換や長時間録音の幻覚ループからの復旧も扱います。
主な機能
- 0116 kHz WAV 音声の抽出
- 02whisper.cpp によるローカル文字起こし
- 03パイプライン用形式への変換
- 04長時間配信の幻覚ループ修復
活用シーン
- 01字幕のない動画の文字起こし
- 02長時間配信の録画処理
- 03動画分割用の文字起こし準備
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ zenithth/ anibon-stream-synthesis --skill anibon-local-transcriptionインストール後、Claude Code で/anibon-local-transcriptionを入力して読み込まれたか確認します。
詳細
Anibon ローカル音声文字起こし
概要とトリガー
対象の動画に YouTube の字幕や自動生成字幕がない場合に使用します。
1. 音声の抽出
一時ファイルの作成と、8 時間以上の長いストリームで WAV ヘッダーが 4 GB を超える問題を避けるため、音声ストリームをモノラル、16 kHz、16 ビット PCM WAV として直接ダウンロードします。
# Direct single-pass extraction via yt-dlp + ffmpeg:
yt-dlp -f ba -x --audio-format wav --postprocessor-args "ExtractAudio:-ar 16000 -ac 1 -c:a pcm_s16le" -o "audio_16k.%(ext)s" "VIDEO_URL"
メモ
YouTube が
HTTP Error 403: Forbiddenを返す場合は、まず yt-dlp を更新してください。yt-dlp --update
または、既存の音声を変換します。
ffmpeg -i audio.wav -ar 16000 -ac 1 -c:a pcm_s16le audio_16k.wav
2. ローカルでの文字起こし
GPU アクセラレーション対応の whisper.cpp ビルドを実行します。
システムの PATH またはローカルの $HOME/whisper.cpp ビルドディレクトリに whisper-cli があるか確認します。
$HOME/whisper.cpp/build/bin/whisper-cli(Windows では.exe)$HOME/whisper.cpp/main
モデルのパスは、デフォルトで $HOME/whisper.cpp/models/ggml-large-v3-turbo.bin です。
実行:
# Linux/macOS
whisper-cli -m models/ggml-large-v3-turbo.bin -f audio_16k.wav -l th -ot 240000 -t 8 --output-json -of whisper_output
# Windows (Vulkan Device 0: RX 7600, or Device 1: Tesla P100):
C:\Users\peter\whisper.cpp\build\bin\whisper-cli.exe -m C:\Users\peter\whisper.cpp\models\ggml-large-v3-turbo.bin -f audio_16k.wav -ot 240000 -l th -t 8 --output-json -of whisper_output --print-progress
(-ot 240000 は、無音部分での繰り返しループのバグを避けるため、冒頭の待機/イントロの無音部分を 4 分スキップします。)
ビルドオプションとプラットフォーム設定の全容については、BUILD_WHISPERCPP_GUILD.md を参照してください。
3. 形式変換と Windows の不変条件
whisper_output.json をパイプライン標準の raw_transcript.json に直接変換します。
重要
Windows の UTF-8 不変条件:
- Windows のデフォルトのコンソールエンコーディング(
cp1252/charmap)では、タイ語のテキストを出力するとクラッシュします。スクリプトは必ずpython -X utf8で実行してください。- MSVC の
whisper-cliの出力では、セグメントバッファーの分割位置によって、マルチバイトのタイ語 UTF-8 文字が分割されることがあります。JSON は必ずerrors="replace"を指定してデコードしてください。
インライン Python コンバーターを実行します。
python -X utf8 -c "
import json
def fmt_ts(seconds):
h = int(seconds // 3600)
m = int((seconds % 3600) // 60)
s = int(seconds % 60)
return f'{h:02d}:{m:02d}:{s:02d}'
with open('whisper_output.json', 'rb') as f:
data = json.loads(f.read().decode('utf-8', errors='replace'))
items = []
for seg in data.get('transcription', []):
text = seg.get('text', '').strip()
if not text:
continue
offsets = seg.get('offsets', {})
start_sec = offsets.get('from', 0) / 1000.0
end_sec = offsets.get('to', 0) / 1000.0
items.append({
'text': text,
'start': round(start_sec, 2),
'duration': round(end_sec - start_sec, 2),
'timestamp': fmt_ts(start_sec)
})
with open('raw_transcript.json', 'w', encoding='utf-8') as out:
json.dump(items, out, ensure_ascii=False, indent=2)
"
4. ハルシネーションの検出と復旧
2 時間以上のライブ配信では、Whisper が音楽や無音部分でループすることがあります。並列分割統治方式の復旧処理を実行します。
python -X utf8 ..\whisper-corruption-recovery\scripts\fix_hallucinations.py whisper_output.json audio_16k.wav --devices 0 -w 3 -o raw_transcript.json
続いて、prepare_video.py を使ってチャンク分割を実行します。
python -X utf8 scripts\prepare_video.py <VIDEO_URL> --workspace <WORKSPACE> --format txt --block 300 --overlap 30