OpenAIが提供する「Whisper」は、音声認識を行うためのオープンソースモデルです。
Pythonを使うことで、音声ファイルから簡単に文字起こしが可能です。
Whisperをそのまま使うと解析速度が遅いため、faster-whisperを使って高速化します。
faster-whisperは、Transformerモデル用の高速推論エンジンであるCTranslate2を使用してOpenAIのWhisperモデルを再実装したものです。
以下はGoogle Colaboratoryを利用してCPU利用で、英語の音声を文字起こしするサンプルです。
!pip install git+https://github.com/openai/whisper.git
!pip install faster-whisper
# モジュールをインポート
from faster_whisper import WhisperModel
# cpuモデルをロード(base モデルを例として使用)
model = WhisperModel("base", device="cpu")
# 音声ファイルのパスを指定
audio_path = "/content/sample_data/test_xxx.mp3"
# 英語の音声の文字起こしを実行
segments, info = model.transcribe(audio_path, beam_size=5, language="en")
# 結果をテキストに変換
text = ""
for segment in segments:
text += segment.text + "\n"
# 結果をファイルに書き込み
with open("/content/sample_data/output_6.txt", "w", encoding="utf-8") as file:
file.write(text)
print("文字起こしが完了しました。")