Test Audio Transcription with ElevenLabs
Promptfoo example testing ElevenLabs speech-to-text: diarization, Word Error Rate scoring, cost, and 30+ languages.
Why it matters
Automate the testing of audio transcription capabilities using the ElevenLabs STT provider. Ensure your audio processing pipelines are robust and accurate.
Outcomes
What it gets done
Integrate ElevenLabs STT provider into your testing framework.
Transcribe audio files for quality assurance.
Validate the accuracy of transcribed text.
Streamline audio transcription testing processes.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-stt | bash Steps
Steps in the chain
Overview
Stt
A promptfoo example testing ElevenLabs speech-to-text transcription, covering Word Error Rate scoring, speaker diarization, cost tracking, and 30+ supported languages. Use when validating ElevenLabs STT accuracy, diarization, cost, or language/quality behavior before relying on it in a production transcription pipeline.
What it does
This example demonstrates how to use the ElevenLabs STT provider for audio transcription testing. Core features covered: audio transcription with high accuracy, speaker diarization to identify and separate multiple speakers, Word Error Rate (WER) measurement against a reference text, and multi-format audio support (MP3, MP4/M4A, WAV, FLAC, OGG, Opus, WebM). WER is calculated as (Substitutions + Deletions + Insertions) / Total Words; a sample response reports wer: 0.05 with per-word substitution/deletion/insertion counts and an aligned reference-vs-hypothesis diff. WER bands: 0.00-0.05 excellent (95%+ accurate), 0.05-0.10 good, 0.10-0.20 fair, 0.20+ poor (under 80% accurate).
When to use - and when NOT to
Use this example when you need to validate transcription accuracy (via WER against a known reference), test speaker diarization, or benchmark cost/latency for ElevenLabs STT across different audio qualities or languages. It is not a general audio-processing example - noise cleanup is covered separately by the related ElevenLabs Isolation example, and voice synthesis by the ElevenLabs TTS example.
Inputs and outputs
Set ELEVENLABS_API_KEY, create an audio/ directory with test files, then scaffold and run:
npx promptfoo@latest init --example provider-elevenlabs/stt
cd provider-elevenlabs/stt
export ELEVENLABS_API_KEY=your_api_key_here
npx promptfoo@latest eval
Audio can be supplied at the config level (config.audioFile), prompt level (listing audio file paths directly as prompts), or vars level (vars.audioFile). Diarization is enabled with diarization: true and an optional maxSpeakers hint, returning a diarization array of per-speaker segments with speaker_id, text, start_time_ms/end_time_ms, and confidence. Assertions can check cost (type: cost, e.g. threshold 0.05), latency (type: latency, e.g. threshold 10000ms), transcription content (contains/not-contains), a WER ceiling via a javascript assertion reading context.vars.metadata?.wer?.wer, or expected speaker count by counting unique speaker_ids in the diarization array. Config options include modelId (default eleven_speech_to_text_v1), language (ISO 639-1, default auto-detect), diarization, maxSpeakers, audioFile, audioFormat, referenceText and calculateWER for WER scoring, baseUrl (default https://api.elevenlabs.io/v1), timeout (default 120000ms), and retries (default 3).
Integrations
Integrates the ElevenLabs Speech-to-Text API as promptfoo providers (elevenlabs:stt, elevenlabs:stt:basic, elevenlabs:stt:diarization, elevenlabs:stt:accuracy, or per-language variants like elevenlabs:stt:english/elevenlabs:stt:spanish). It supports 30+ languages via ISO 639-1 codes (en, es, fr, de, it, pt, ja, ko, zh, etc.) or automatic language detection when language is omitted. Pricing is duration-based: a free tier of 1 hour/month, then roughly $0.10 per minute (~$0.00167/second) on paid tiers, with costs automatically tracked in eval results. Advanced patterns shown include batch transcription across multiple audio files with shared cost/latency assertions, multi-language comparison configs, and accuracy comparison across audio qualities (48kHz, 16kHz, 8kHz) with quality-specific WER thresholds.
Who it's for
Teams evaluating ElevenLabs STT for production transcription pipelines who need to validate accuracy via WER, verify multi-speaker diarization, track cost and latency, and confirm behavior across languages and audio quality levels before relying on it - including troubleshooting guidance for missing API keys, file-not-found errors, unsupported formats (convertible via ffmpeg -i input.video -vn -acodec mp3 output.mp3), and unexpectedly high WER on clear audio (often due to reference-text mismatches or wrong language auto-detection).
Source README
provider-elevenlabs/stt (ElevenLabs Speech-to-Text)
This example demonstrates how to use ElevenLabs STT provider for audio transcription testing.
Quick Start
npx promptfoo@latest init --example provider-elevenlabs/stt
cd provider-elevenlabs/stt
export ELEVENLABS_API_KEY=your_api_key_here
npx promptfoo@latest eval
Features
- Audio Transcription: Convert speech to text with high accuracy
- Speaker Diarization: Identify and separate multiple speakers in audio
- Word Error Rate (WER): Measure transcription accuracy against reference text
- Multi-format Support: MP3, WAV, FLAC, M4A, OGG, OPUS, WebM
Setup
Set your API key:
export ELEVENLABS_API_KEY=your_api_key_herePrepare audio files:
Create anaudio/directory with your test audio files:mkdir -p audio # Place your audio files in the audio/ directoryRun the evaluation:
promptfoo eval
Configuration
Basic Transcription
providers:
- id: elevenlabs:stt:basic
config:
modelId: eleven_speech_to_text_v1
language: en # ISO 639-1 language code
Speaker Diarization
Identify and label different speakers in your audio:
providers:
- id: elevenlabs:stt:diarization
config:
modelId: eleven_speech_to_text_v1
diarization: true
maxSpeakers: 3 # Optional: hint for expected number of speakers
The response will include speaker segments:
{
"text": "Full transcription...",
"diarization": [
{
"speaker_id": "speaker_0",
"text": "Hello, how are you?",
"start_time_ms": 0,
"end_time_ms": 2500,
"confidence": 0.95
},
{
"speaker_id": "speaker_1",
"text": "I'm doing well, thanks!",
"start_time_ms": 2500,
"end_time_ms": 5000,
"confidence": 0.92
}
]
}
Accuracy Testing with WER
Word Error Rate (WER) measures transcription accuracy. Lower is better (0 = perfect).
providers:
- id: elevenlabs:stt:accuracy
config:
modelId: eleven_speech_to_text_v1
calculateWER: true
referenceText: The quick brown fox jumps over the lazy dog
WER Formula: (Substitutions + Deletions + Insertions) / Total Words
The response includes detailed WER metrics:
{
"wer": 0.05, // 5% error rate
"substitutions": 1,
"deletions": 0,
"insertions": 0,
"correct": 19,
"totalWords": 20,
"details": {
"reference": "the quick brown fox jumps",
"hypothesis": "the quick green fox jumps",
"alignment": "REF: the quick brown fox jumps\nHYP: the quick green fox jumps\nOPS: SSSSS"
}
}
WER Interpretation:
- 0.00 - 0.05: Excellent (95%+ accurate)
- 0.05 - 0.10: Good (90-95% accurate)
- 0.10 - 0.20: Fair (80-90% accurate)
- 0.20+: Poor (< 80% accurate)
Supported Audio Formats
| Format | Extension | Notes |
|---|---|---|
| MP3 | .mp3 | Widely compatible |
| MP4 Audio | .mp4, .m4a | AAC/MPEG-4 audio |
| WAV | .wav | Uncompressed, high quality |
| FLAC | .flac | Lossless compression |
| OGG | .ogg | Open format |
| Opus | .opus | Modern, efficient codec |
| WebM | .webm | Web-optimized |
Audio Input Methods
Method 1: Config-level
providers:
- id: elevenlabs:stt
config:
audioFile: path/to/audio.mp3
Method 2: Prompt-level
prompts:
- audio/sample1.mp3
- audio/sample2.wav
Method 3: Vars-level
tests:
- vars:
audioFile: audio/sample.mp3
Testing Assertions
Cost Threshold
tests:
- assert:
- type: cost
threshold: 0.05 # Max $0.05 per transcription
Latency Threshold
tests:
- assert:
- type: latency
threshold: 10000 # Max 10 seconds
Transcription Quality
tests:
- assert:
- type: contains
value: expected phrase
- type: not-contains
value: incorrect phrase
WER Threshold
tests:
- assert:
- type: javascript
value: |
const wer = context.vars.metadata?.wer?.wer || 1;
wer < 0.1 // Less than 10% error
Speaker Count
tests:
- assert:
- type: javascript
value: |
const diarization = context.vars.metadata?.transcription?.diarization || [];
const uniqueSpeakers = new Set(diarization.map(s => s.speaker_id));
uniqueSpeakers.size === 2 // Expect 2 speakers
Language Support
ElevenLabs STT supports 30+ languages. Specify using ISO 639-1 codes:
config:
language: en # English
# language: es # Spanish
# language: fr # French
# language: de # German
# language: it # Italian
# language: pt # Portuguese
# language: ja # Japanese
# language: ko # Korean
# language: zh # Chinese
Auto-detection: Omit language to let the API detect the language automatically.
Cost Information
STT pricing is based on audio duration:
- Free tier: 1 hour/month
- Paid tiers:
$0.10 per minute ($0.00167 per second)
The provider automatically tracks and reports costs in the evaluation results.
Advanced Usage
Batch Transcription
prompts:
- audio/batch1.mp3
- audio/batch2.mp3
- audio/batch3.mp3
providers:
- id: elevenlabs:stt
config:
modelId: eleven_speech_to_text_v1
### Test all files with consistent assertions
tests:
- assert:
- type: cost
threshold: 0.10
- type: latency
threshold: 15000
Multi-language Testing
providers:
- id: elevenlabs:stt:english
config:
language: en
- id: elevenlabs:stt:spanish
config:
language: es
- id: elevenlabs:stt:autodetect
config:
# No language specified = auto-detect
prompts:
- audio/english_sample.mp3
- audio/spanish_sample.mp3
Accuracy Comparison
Compare transcription accuracy across different audio qualities:
prompts:
- audio/high_quality_48khz.wav
- audio/medium_quality_16khz.mp3
- audio/low_quality_8khz.mp3
providers:
- id: elevenlabs:stt
config:
calculateWER: true
referenceText: This is the expected transcription text
tests:
- description: High quality should have WER < 5%
vars:
audioFile: audio/high_quality_48khz.wav
assert:
- type: javascript
value: (context.vars.metadata?.wer?.wer || 1) < 0.05
- description: Medium quality should have WER < 10%
vars:
audioFile: audio/medium_quality_16khz.mp3
assert:
- type: javascript
value: (context.vars.metadata?.wer?.wer || 1) < 0.10
Troubleshooting
API Key Issues
### Verify your API key is set
echo $ELEVENLABS_API_KEY
### Or set it inline
ELEVENLABS_API_KEY=your_key promptfoo eval
Audio File Not Found
Error: Failed to read audio file: ENOENT: no such file or directory
Solution: Use absolute paths or paths relative to the config file:
prompts:
- /absolute/path/to/audio.mp3
- ./relative/path/to/audio.mp3
Unsupported Format
Error: Unsupported audio format
Solution: Convert your audio to a supported format (MP3, WAV, etc.) using tools like ffmpeg:
ffmpeg -i input.video -vn -acodec mp3 output.mp3
High WER on Clear Audio
If you're getting unexpectedly high WER:
- Check reference text - ensure it exactly matches the audio (including punctuation)
- Specify language - auto-detection may choose the wrong language
- Audio quality - ensure audio is clear with minimal background noise
- Normalization - WER calculation normalizes text (lowercase, removes punctuation)
API Reference
Config Options
| Option | Type | Default | Description |
|---|---|---|---|
modelId |
string | eleven_speech_to_text_v1 |
STT model to use |
language |
string | auto-detect | ISO 639-1 language code |
diarization |
boolean | false |
Enable speaker identification |
maxSpeakers |
number | - | Expected number of speakers |
audioFile |
string | - | Path to audio file |
audioFormat |
string | auto-detect | Audio format override |
referenceText |
string | - | Expected transcription for WER |
calculateWER |
boolean | false |
Calculate Word Error Rate |
baseUrl |
string | https://api.elevenlabs.io/v1 |
API endpoint |
timeout |
number | 120000 |
Request timeout (ms) |
retries |
number | 3 |
Number of retry attempts |
Related Examples
- ElevenLabs TTS - Text-to-Speech synthesis
- ElevenLabs Isolation - Audio cleanup quality comparison
Resources
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.