Faster Whisperで文字起こしする

Faster Whisperを用いて文字起こしをするための備忘録です。

環境構築

Ubuntu20.04上に構築することを想定。

PythonとFFmpegのインストール

sudo apt update
sudo apt install ffmpeg python3 python3-pip

uvのインストール

pip install uv

仮想環境の作成

uv venv -p 3.12 .venv312
source .venv312/bin/activate

faster-whisperをインストール

uv pip install faster-whisper

huggingface_hubのインストール

※uvを使うと入らなかった

pip install huggingface_hub

モデルのダウンロード

smallモデルのダウンロードを想定

mkdir faster-whisper
cd faster-whisper

huggingface-cli download guillaumekln/faster-whisper-small --local-dir small

HF Hubの無効化

以下を.bashrcに追加

export HF_HUB_OFFLINE=1
export HF_HUB_DISABLE_TELEMETRY=1

サンプルコードの実行

以下が実行できればOK

from 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}")