speech-to-text について
ElevenLabs Speech-to-Textは、Scribe v2で音声を文字に変換するスキルで、録音やライブ音声を扱うアプリケーション向けです。多言語対応に加え、話者の識別、単語単位のタイムスタンプ、リアルタイム配信を備えています。
主な機能
- 0190以上の言語の文字起こし
- 02話者の識別と役割ラベル
- 03単語単位のタイムスタンプ
- 04キータームの指定
- 05リアルタイム文字起こし
活用シーン
- 01長時間録音から字幕を作成
- 02会議の発言を話者別に文字起こし
- 03音声をリアルタイムでテキスト表示
- 04製品名や専門用語の認識
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ marks97/ speech-to-text --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/*パッケージのみを使用してください。
API キー
呼び出しを行う前に、環境変数に ELEVENLABS_API_KEY を設定してください(https://elevenlabs.io で取得できます)。
export ELEVENLABS_API_KEY="your-api-key"
キーの値を文字起こしに出力したり、コミットしたりしないでください。
クイックスタート
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}")
通話の録音では、diarize=true とともに detect_speaker_roles=true を設定すると、バッチ API でダイアライゼーションされた話者に agent と customer のラベルを付けられます。このオプションは use_multi_channel=true と併用できません。
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" \
-F "diarize=true" \
-F "detect_speaker_roles=true"
キータームプロンプト
モデルが誤認識する可能性のある特定の単語(製品名、専門用語、珍しいスペルなど)の認識を補助します(最大 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 | エラーが発生しました |
完全なドキュメントについては、リアルタイム関連のリファレンスを参照してください。