kotoba-whisper-v2.2
Gated model You have been granted access to this model
apt update apt install -y sudo wget git curl python3 python3-dev python3-pip ffmpeg
# python 仮想環境の状態で以下実行する。 pip install --upgrade pip # pytorch 関連をインストールする。 # https://pytorch.org/ の Install PyTorch にて、自分の環境に合わせて選択し、表示されるコマンドを実行のこと pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 pip python-multipart # kotoba-whisper-v2.2 に記載されている必要なライブラリをインストール pip --upgrade transformers accelerate torchaudio pip install "punctuators==0.0.5" pip install "pyannote.audio"
test.py
import torch
from transformers import pipeline
# config
model_id = "kotoba-tech/kotoba-whisper-v2.2"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
# load model
pipe = pipeline(
model=model_id,
torch_dtype=torch_dtype,
device=device,
model_kwargs=model_kwargs,
batch_size=8,
trust_remote_code=True,
)
# run inference
result = pipe("sample_diarization_japanese.mp3", chunk_length_s=15)
print(result)
# sample_diarization_japanese.mp3
# を自分で音声ファイルを作成する場合は、次で作ると良い。(16KHz, モノラル であれば良い)
# arecord -r 16000 --vumeter=mono test.wav
git config --global credential.helper store # git 認証情報保存するために実行 huggingface-cli login --token "★ここに huggingface で取得したトークンを入れる★" --add-to-git-credential
python test.py※初回、ダウンロード等のため時間かかります。
~/.cache/huggingface/hub/
wav ファイルを送信すると、音声認識結果を返す REST API
pip install fastapi uvicorn uvicorn kotoba-whisper-server:app --host 0.0.0.0 --port 50022
curl
https://ehobby.jp/gitbucket/git/kei-n/kotoba-whisper.git
git pull https://ehobby.jp/gitbucket/git/kei-n/kotoba-whisper.git curl -X POST http://127.0.0.1:50022/transcribe -F "file=@sample.wav"
※sample.wav ファイルは、事前に 16kHz, モノラルで録音した音声ファイル
https://ehobby.jp/gitbucket/kei-n/kotoba-whisper 参照
git clone https://ehobby.jp/gitbucket/git/kei-n/kotoba-whisper.git cd kotoba-whisper # Huggingface でトークンを作成しておくこと。 # https://huggingface.co/pyannote/speaker-diarization-3.1 の利用許諾を得ておくこと。 echo "HF_TOKEN=<Huggingface で取得したトークン>" > .env # Docker イメージ作成 (GPU対応の設定、kotoba-whsper インストール等含む) docker-compose build # 起動 docker-compose up -d # REST API サーバーが起動する。 # あとは、次のコマンド等で音声認識させる。 git pull https://ehobby.jp/gitbucket/git/kei-n/kotoba-whisper.git curl -X POST http://127.0.0.1:50022/transcribe -F "file=@sample.wav"
※sample.wav ファイルは、事前に 16kHz, モノラルで録音した音声ファイル
参考URL: https://huggingface.co/kotoba-tech/kotoba-whisper-v2.2