speech-to-text について
speech-to-textは、ElevenLabs Scribe v2で音声や動画を文字起こしするスキルです。一括処理とリアルタイム処理に対応し、言語検出、話者識別、単語単位のタイムスタンプ、キーワード指定を扱います。
主な機能
- 01一括およびリアルタイム文字起こし
- 0290以上の言語に対応
- 03話者識別
- 04単語単位のタイムスタンプ
- 05キーワード指定と言語検出
活用シーン
- 01話者ラベル付きでインタビュー録音を文字起こし
- 02長時間音声から単語タイミング付き字幕を作成
- 03マイク入力の文字起こしをリアルタイム表示
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ calesthio/ openmontage --skill speech-to-textインストール後、Claude Code で/speech-to-textを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/installation.mdrealtime-client-side.mdrealtime-commit-strategies.mdrealtime-events.mdrealtime-server-side.mdtranscription-options.md詳細
ElevenLabs Speech-to-Text
Scribe v2 で音声をテキストに文字起こしします。90 以上の言語、話者ダイアライゼーション、単語レベルのタイムスタンプに対応しています。
セットアップ: インストールガイドをご覧ください。JavaScript では、
@elevenlabs/*パッケージのみを使用してください。
クイックスタート
Python
from elevenlabs import ElevenLabs
client = ElevenLabs()
with open("audio.mp3", "rb") as audio_file:
result = client.speech_to_text.convert(file=audio_file, model_id="scribe_v2")
print(result.text)
JavaScript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { createReadStream } from "fs";
const client = new ElevenLabsClient();
const result = await client.speechToText.convert({
file: createReadStream("audio.mp3"),
modelId: "scribe_v2",
});
console.log(result.text);
cURL
curl -X POST "https://api.elevenlabs.io/v1/speech-to-text" \
-H "xi-api-key: $ELEVENLABS_API_KEY" -F "[email protected]" -F "model_id=scribe_v2"
モデル
| モデル ID | 説明 | 最適な用途 |
|---|---|---|
scribe_v2 | 最先端の精度、90 以上の言語 | バッチ文字起こし、字幕、長時間の音声 |
scribe_v2_realtime | 低レイテンシー(約 150ms) | ライブ文字起こし、音声エージェント |
タイムスタンプ付き文字起こし
単語レベルのタイムスタンプには、種別の分類と話者の識別が含まれます。
result = client.speech_to_text.convert(
file=audio_file, model_id="scribe_v2", timestamps_granularity="word"
)
for word in result.words:
print(f"{word.text}: {word.start}s - {word.end}s (type: {word.type})")
話者ダイアライゼーション
誰が何を話したかを識別します。モデルは各単語に話者 ID を付与するため、会議やインタビューなど、複数の話者がいる音声で役立ちます。
result = client.speech_to_text.convert(
file=audio_file,
model_id="scribe_v2",
diarize=True
)
for word in result.words:
print(f"[{word.speaker_id}] {word.text}")
キータームのプロンプト指定
製品名、専門用語、特殊な綴りなど、モデルが聞き間違える可能性のある単語を認識できるようにします(最大 100 語)。
result = client.speech_to_text.convert(
file=audio_file,
model_id="scribe_v2",
keyterms=["ElevenLabs", "Scribe", "API"]
)
言語検出
言語のヒントを任意で指定でき、自動検出に対応しています。
result = client.speech_to_text.convert(
file=audio_file,
model_id="scribe_v2",
language_code="eng" # ISO 639-1 or ISO 639-3 code
)
print(f"Detected: {result.language_code} ({result.language_probability:.0%})")
対応形式
音声: MP3、WAV、M4A、FLAC、OGG、WebM、AAC、AIFF、Opus 動画: MP4、AVI、MKV、MOV、WMV、FLV、WebM、MPEG、3GPP
制限: ファイルサイズは最大 3GB、長さは最大 10 時間
レスポンス形式
{
"text": "The full transcription text",
"language_code": "eng",
"language_probability": 0.98,
"words": [
{"text": "The", "start": 0.0, "end": 0.15, "type": "word", "speaker_id": "speaker_0"},
{"text": " ", "start": 0.15, "end": 0.16, "type": "spacing", "speaker_id": "speaker_0"}
]
}
単語の種別:
word- 実際に発話された単語spacing- 単語間の空白(正確なタイミングの把握に便利です)audio_event- モデルが検出した音声以外の音(笑い声、拍手、音楽など)
エラー処理
try:
result = client.speech_to_text.convert(file=audio_file, model_id="scribe_v2")
except Exception as e:
print(f"Transcription failed: {e}")
よくあるエラー:
- 401:API キーが無効です
- 422:パラメーターが無効です
- 429:レート制限を超えました
コストの追跡
request-id レスポンスヘッダーを使って使用状況を監視します。
response = client.speech_to_text.convert.with_raw_response(file=audio_file, model_id="scribe_v2")
result = response.parse()
print(f"Request ID: {response.headers.get('request-id')}")
リアルタイムストリーミング
超低レイテンシー(約 150ms)でライブ文字起こしを行うには、リアルタイム API を使用してください。リアルタイム API では、2 種類の文字起こし結果が生成されます。
- 部分文字起こし: 音声の処理中に頻繁に更新される暫定結果です。ライブでのフィードバック(例:ユーザーの発話に合わせてテキストを表示する場合)に使用します。
- 確定済み文字起こし: 「コミット」した後の、最終的で安定した結果です。アプリケーションの確定データとして使用します。
「コミット」とは、現在のセグメントを確定するようモデルに指示することです。手動でコミットする(例:ユーザーが一時停止したとき)か、音声活動検出(VAD)を使用して無音時に自動コミットできます。
Python(サーバーサイド)
import asyncio
from elevenlabs import ElevenLabs
client = ElevenLabs()
async def transcribe_realtime():
async with client.speech_to_text.realtime.connect(
model_id="scribe_v2_realtime",
include_timestamps=True,
) as connection:
await connection.stream_url("https://example.com/audio.mp3")
async for event in connection:
if event.type == "partial_transcript":
print(f"Partial: {event.text}")
elif event.type == "committed_transcript":
print(f"Final: {event.text}")
asyncio.run(transcribe_realtime())
JavaScript(React を使ったクライアントサイド)
import { useScribe, CommitStrategy } from "@elevenlabs/react";
function TranscriptionComponent() {
const [transcript, setTranscript] = useState("");
const scribe = useScribe({
modelId: "scribe_v2_realtime",
commitStrategy: CommitStrategy.VAD, // Auto-commit on silence for mic input
onPartialTranscript: (data) => console.log("Partial:", data.text),
onCommittedTranscript: (data) => setTranscript((prev) => prev + data.text),
});
const start = async () => {
// Get token from your backend (never expose API key to client)
const { token } = await fetch("/scribe-token").then((r) => r.json());
await scribe.connect({
token,
microphone: { echoCancellation: true, noiseSuppression: true },
});
};
return <button onClick={start}>Start Recording</button>;
}
コミット方式
| 方式 | 説明 |
|---|---|
| 手動 | 準備ができたら commit() を呼び出します。ファイル処理や、音声セグメントを制御できる場合に使用します |
| VAD | 音声活動検出により、無音が検知されると自動でコミットします。ライブマイク入力に使用します |
// React: set commitStrategy on the hook (recommended for mic input)
import { useScribe, CommitStrategy } from "@elevenlabs/react";
const scribe = useScribe({
modelId: "scribe_v2_realtime",
commitStrategy: CommitStrategy.VAD,
// Optional VAD tuning:
vadSilenceThresholdSecs: 1.5,
vadThreshold: 0.4,
});
// JavaScript client: pass vad config on connect
const connection = await client.speechToText.realtime.connect({
modelId: "scribe_v2_realtime",
vad: {
silenceThresholdSecs: 1.5,
threshold: 0.4,
},
});
イベント種別
| イベント | 説明 |
|---|---|
partial_transcript | ライブの暫定結果 |
committed_transcript | コミット後の最終結果 |
committed_transcript_with_timestamps | 単語ごとのタイミングを含む最終結果 |
error | エラーが発生しました |
詳しくは、リアルタイム関連のリファレンスをご覧ください。