AI

音声認識 (kotoba-whisper)

kotoba-whisper-v2.2

特徴

利用にあたって

インストール

サンプルプログラム用意

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

実行

REST API 化

wav ファイルを送信すると、音声認識結果を返す REST API

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, モノラルで録音した音声ファイル

上記 Docker

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

トップ   差分 バックアップ リロード   一覧 検索 最終更新   ヘルプ   最終更新のRSS