Faster Whisperで文字起こしする
Faster Whisperを用いて文字起こしをするための備忘録です。
環境構築
Ubuntu20.04上に構築することを想定。
PythonとFFmpegのインストール
copy_allsudo apt update
sudo apt install ffmpeg python3 python3-pip
uvのインストール
copy_allpip install uv
仮想環境の作成
copy_alluv venv -p 3.12 .venv312
source .venv312/bin/activate
faster-whisperをインストール
copy_alluv pip install faster-whisper
huggingface_hubのインストール
※uvを使うと入らなかった
copy_allpip install huggingface_hub
モデルのダウンロード
smallモデルのダウンロードを想定
copy_allmkdir faster-whisper
cd faster-whisper
huggingface-cli download guillaumekln/faster-whisper-small --local-dir small
HF Hubの無効化
以下を.bashrcに追加
copy_allexport HF_HUB_OFFLINE=1
export HF_HUB_DISABLE_TELEMETRY=1
サンプルコードの実行
以下が実行できればOK
copy_allfrom faster_whisper import WhisperModel
model = WhisperModel(
"./small", # ダウンロードしたモデルのパスを指定
device="cpu", # CPUのみを使用
compute_type="int8",
)
segments, info = model.transcribe("test.wav")
print("Detected language:", info.language)
for seg in segments:
print(f"[{seg.start:.2f} → {seg.end:.2f}] {seg.text}")