mcpField
W
whisper

whisper

github.com/davila7クリエイティブ・メディア33.0k1.5k 回インストール今日更新
リポジトリ

whisper について

Whisperは、音声の文字起こしや英語への翻訳に使えるOpenAIの多言語音声認識モデルです。コマンドラインとPythonで録音を処理でき、複数のモデルサイズやタイムスタンプ設定を備えています。

主な機能

  1. 0199言語の文字起こし
  2. 02音声を英語に翻訳
  3. 03単語単位のタイムスタンプ
  4. 04複数のモデルサイズ
  5. 05テキストと字幕形式で出力
  6. 06利用可能な場合のGPUアクセラレーション

活用シーン

  1. 01ポッドキャストや動画の文字起こし
  2. 02会議音声からの議事メモ作成
  3. 03英語以外の音声の英訳
  4. 04SRT字幕の生成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/davila7/claude-code-templates --skill whisper

インストール後、Claude Code で/whisperを入力して読み込まれたか確認します。

同梱ファイルreferences/languages.md

詳細

Whisper - 堅牢な音声認識

OpenAI の多言語音声認識モデルです。

Whisper を使うべき場面

使用に適した場面:

  • 音声からテキストへの文字起こし(99 言語)
  • ポッドキャストや動画の文字起こし
  • 議事録の自動化
  • 英語への翻訳
  • ノイズの多い音声の文字起こし
  • 多言語の音声処理

指標:

  • 72,900+ GitHub スター
  • 対応言語 99 種
  • 680,000 時間の音声で学習
  • MIT ライセンス

代わりに検討すべきサービス:

  • AssemblyAI: マネージド API、話者分離
  • Deepgram: リアルタイムのストリーミング ASR
  • Google Speech-to-Text: クラウドベース

クイックスタート

インストール
# Requires Python 3.8-3.11
pip install -U openai-whisper

# Requires ffmpeg
# macOS: brew install ffmpeg
# Ubuntu: sudo apt install ffmpeg
# Windows: choco install ffmpeg
基本的な文字起こし
import whisper

# Load model
model = whisper.load_model("base")

# Transcribe
result = model.transcribe("audio.mp3")

# Print text
print(result["text"])

# Access segments
for segment in result["segments"]:
    print(f"[{segment['start']:.2f}s - {segment['end']:.2f}s] {segment['text']}")

モデルサイズ

# Available models
models = ["tiny", "base", "small", "medium", "large", "turbo"]

# Load specific model
model = whisper.load_model("turbo")  # Fastest, good quality
ModelParametersEnglish-onlyMultilingualSpeedVRAM
tiny39M✓✓~32x~1 GB
base74M✓✓~16x~1 GB
small244M✓✓~6x~2 GB
medium769M✓✓~2x~5 GB
large1550M✗✓1x~10 GB
turbo809M✗✓~8x~6 GB

推奨: 速度と品質のバランスが最良の turbo、プロトタイピング用には base を使用してください

文字起こしオプション

言語の指定
# Auto-detect language
result = model.transcribe("audio.mp3")

# Specify language (faster)
result = model.transcribe("audio.mp3", language="en")

# Supported: en, es, fr, de, it, pt, ru, ja, ko, zh, and 89 more
タスクの選択
# Transcription (default)
result = model.transcribe("audio.mp3", task="transcribe")

# Translation to English
result = model.transcribe("spanish.mp3", task="translate")
# Input: Spanish audio → Output: English text
初期プロンプト
# Improve accuracy with context
result = model.transcribe(
    "audio.mp3",
    initial_prompt="This is a technical podcast about machine learning and AI."
)

# Helps with:
# - Technical terms
# - Proper nouns
# - Domain-specific vocabulary
タイムスタンプ
# Word-level timestamps
result = model.transcribe("audio.mp3", word_timestamps=True)

for segment in result["segments"]:
    for word in segment["words"]:
        print(f"{word['word']} ({word['start']:.2f}s - {word['end']:.2f}s)")
温度フォールバック
# Retry with different temperatures if confidence low
result = model.transcribe(
    "audio.mp3",
    temperature=(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
)

コマンドラインでの使用

# Basic transcription
whisper audio.mp3

# Specify model
whisper audio.mp3 --model turbo

# Output formats
whisper audio.mp3 --output_format txt     # Plain text
whisper audio.mp3 --output_format srt     # Subtitles
whisper audio.mp3 --output_format vtt     # WebVTT
whisper audio.mp3 --output_format json    # JSON with timestamps

# Language
whisper audio.mp3 --language Spanish

# Translation
whisper spanish.mp3 --task translate

バッチ処理

import os

audio_files = ["file1.mp3", "file2.mp3", "file3.mp3"]

for audio_file in audio_files:
    print(f"Transcribing {audio_file}...")
    result = model.transcribe(audio_file)

    # Save to file
    output_file = audio_file.replace(".mp3", ".txt")
    with open(output_file, "w") as f:
        f.write(result["text"])

リアルタイム文字起こし

# For streaming audio, use faster-whisper
# pip install faster-whisper

from faster_whisper import WhisperModel

model = WhisperModel("base", device="cuda", compute_type="float16")

# Transcribe with streaming
segments, info = model.transcribe("audio.mp3", beam_size=5)

for segment in segments:
    print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")

GPU アクセラレーション

import whisper

# Automatically uses GPU if available
model = whisper.load_model("turbo")

# Force CPU
model = whisper.load_model("turbo", device="cpu")

# Force GPU
model = whisper.load_model("turbo", device="cuda")

# 10-20× faster on GPU

他のツールとの連携

字幕の生成
# Generate SRT subtitles
whisper video.mp4 --output_format srt --language English

# Output: video.srt
LangChain との併用
from langchain.document_loaders import WhisperTranscriptionLoader

loader = WhisperTranscriptionLoader(file_path="audio.mp3")
docs = loader.load()

# Use transcription in RAG
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

vectorstore = Chroma.from_documents(docs, OpenAIEmbeddings())
動画からの音声抽出
# Use ffmpeg to extract audio
ffmpeg -i video.mp4 -vn -acodec pcm_s16le audio.wav

# Then transcribe
whisper audio.wav

ベストプラクティス

  1. turbo モデルを使用する - 英語では速度と品質のバランスが最良
  2. 言語を指定する - 自動検出より高速
  3. 初期プロンプトを追加する - 専門用語の認識精度が向上
  4. GPU を使用する - 10〜20 倍高速
  5. バッチ処理する - より効率的
  6. WAV に変換する - 互換性が向上
  7. 長い音声は分割する - 30 分以下のチャンクに
  8. 言語サポートを確認する - 品質は言語によって異なる
  9. faster-whisper を使用する - openai-whisper より 4 倍高速
  10. VRAM を監視する - モデルサイズをハードウェアに合わせて調整

パフォーマンス

ModelReal-time factor (CPU)Real-time factor (GPU)
tiny~0.32~0.01
base~0.16~0.01
turbo~0.08~0.01
large~1.0~0.05

リアルタイム係数: 0.1 = リアルタイムの 10 倍速

言語サポート

主なサポート言語:

  • English (en)
  • Spanish (es)
  • French (fr)
  • German (de)
  • Italian (it)
  • Portuguese (pt)
  • Russian (ru)
  • Japanese (ja)
  • Korean (ko)
  • Chinese (zh)

全リスト: 合計 99 言語

制限事項

  1. ハルシネーション - テキストを繰り返したり、存在しない内容を生成したりすることがあります
  2. 長時間音声の精度 - 30 分を超える音声では精度が低下します
  3. 話者識別 - 話者分離には対応していません
  4. アクセント - 品質にばらつきがあります
  5. 背景ノイズ - 精度に影響することがあります
  6. リアルタイムの遅延 - ライブ字幕には適していません

リソース

コメント