Download the PHP package b7s/whisper-php without Composer
On this page you can find all versions of the php package b7s/whisper-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download b7s/whisper-php
More information about b7s/whisper-php
Files in b7s/whisper-php
Package whisper-php
Short Description Transform audio into text with Whisper.cpp AI - directly in PHP
License MIT
Informations about the package whisper-php
✨ Features:
- 🚀 Fast local transcription (no API calls, no costs)
- 🌍 99+ languages supported
- 🎯 High accuracy with multiple model sizes
- 💬 Speaker detection and timestamps
- 📝 Export to SRT, VTT, JSON, CSV
- 🔄 Real-time progress tracking
- 🎨 Fluent Laravel-style API
- 🎬 Video support with automatic audio extraction
- 📦 Smart chunking for large audio/video files
- 🔒 Privacy-first (all processing happens locally)
- 🧪 Real tests (see here)
Requirements
- PHP 8.2 or higher
- Composer 2.x
- curl (for downloads)
- FFmpeg (will be downloaded automatically if not installed)
Installation
After installation, run the setup command to download Whisper binaries and models:
Compile for GPU; if that fails, compile for CPU.
This will download:
- Whisper binary (~50-100 MB)
- Model file (~100-500 MB depending on size)
- FFmpeg binary (~50-80 MB)
Build Dependencies (for compilation)
When running whisper-setup, the library compiles Whisper from source. The following build tools are required:
Linux (Ubuntu/Debian):
macOS:
Other Linux distributions:
- Fedora/RHEL:
sudo dnf install git cmake make gcc-c++ - Arch Linux:
sudo pacman -S git cmake make gcc
These tools are only needed during initial setup. After compilation, they're not required for normal operation.
Setup Options
See Available Models: tiny, tiny.en, base, base.en, small, small.en, medium, medium.en, large
Check Installation Status
This will show:
- Binary installation status
- Model installation status
- FFmpeg availability
- GPU support detection (fallback to CPU)
Basic Usage
Chaining Multiple Options
Switching Models
You can easily switch between models at runtime. The model will be downloaded automatically if not available:
Note: If you experience errors like "not all tensors loaded from model file", your model file may be corrupted. Delete it from
~/.local/share/whisper-php/models/and re-download usingphp ./vendor/bin/whisper-setup --model=<model-name>.See the language tests at Examples Models.
Configuration
The Config class accepts the following parameters:
Parameters:
model: Model to use (default:base) - See Available Models sectionlanguage: Language for transcription (default:auto) - ISO language code or 'auto' for detectiondataDir: Directory to store binaries and models (default:~/.local/share/whisper-php)binaryPath: Custom path to Whisper binary (optional)modelPath: Custom path to model file (optional)ffmpegPath: Custom path to FFmpeg binary (optional)chunkSize: Chunk size for large audio files (default: 20 MB)
Model Installation
Performance Tips
- Start with
base- It's the sweet spot for most applications with multilingual support - Use English-only models when possible - They're faster and more accurate for English (ends with ".en")
- Upgrade to
smallif you need better accuracy - Use
mediumorlargeonly when accuracy is critical (they're much slower) - Use
tinyfor real-time applications or testing
Official Documentation
For more details about Whisper models, see:
Fluent API
The library provides a fluent API for configuring transcriptions. Chain methods to customize the behavior:
Basic Transcription
toEnglish (to English)
What it does: Automatically translates speech from any language to English text. Perfect for multilingual content where you need English output regardless of the spoken language.
Use cases:
- Translating foreign language podcasts to English
- Creating English subtitles for international videos
- Processing multilingual customer support calls
Language Detection and Specification
Automatic Detection (default):
By default, Whisper automatically detects the language being spoken. This works best with multilingual models (base, small, medium, large).
Specify Language for Better Accuracy: If you know the audio language, specifying it improves accuracy and speed:
Use cases:
- Routing calls to appropriate language support teams
- Organizing multilingual audio libraries
- Triggering language-specific processing workflows
- Improving transcription accuracy when language is known
Export Formats (SRT, VTT, JSON, CSV)
What it does: Exports transcriptions with timestamps in various formats for different use cases.
Use cases:
- Creating subtitles for videos (SRT/VTT)
- Building searchable transcription databases (JSON)
- Analyzing speech patterns in spreadsheets (CSV)
improveDecode - Beam Search (Better Quality)
What it does: Uses a more sophisticated decoding algorithm that explores multiple possibilities simultaneously, resulting in more accurate transcriptions at the cost of speed. Higher beam size = better quality but slower.
When to use:
- Important transcriptions where accuracy is critical (legal, medical)
- Audio with difficult accents or background noise
- When you have time and need the best possible result
When NOT to use:
- Real-time or near-real-time transcription
- Processing large volumes of audio quickly
- Audio quality is already very good
filterNonSpeech - Voice Activity Detection (VAD)
What it does: Automatically detects which parts of the audio contain speech vs silence/noise. This improves segmentation by only transcribing actual speech, ignoring long pauses, background music, or silence.
Use cases:
- Podcasts with intro/outro music
- Recordings with long pauses between sentences
- Noisy environments with intermittent speech
- Improving timestamp accuracy
Threshold guide:
0.3- Very sensitive (catches quiet speech, may include some noise)0.5- Balanced (default, good for most cases)0.7- Conservative (only clear speech, may miss quiet parts)
Context Guidance
What it does: Provides context to the AI model BEFORE transcription starts. This "primes" the model to expect certain words, names, or terminology, dramatically improving accuracy for specialized vocabulary that the model might otherwise mishear.
Use cases:
- Medical transcriptions (drug names, procedures)
- Legal transcriptions (case names, legal terms)
- Technical presentations (software terms, acronyms)
- Business meetings (employee names, product names)
- Any domain with specialized vocabulary
Tips:
- Include 5-15 key terms relevant to your audio
- Use actual words/names that will appear in the audio
- Separate terms with commas or natural language
- More specific = better results
Speaker Detection (Experimental)
What it does: Attempts to identify when different people are speaking in a conversation. Each segment gets a speaker ID (0, 1, 2, etc.) indicating who is talking. Note: This doesn't identify WHO the speakers are, just that they're different people.
Use cases:
- Interview transcriptions
- Meeting minutes
- Podcast conversations
- Customer service call analysis
- Multi-speaker presentations
Limitations:
- Experimental feature (may not be 100% accurate)
- Doesn't identify who speakers are (just that they're different)
- Works best with clear audio and distinct voices
- May struggle with overlapping speech
Voice Tone Analysis
What it does: Automatically analyzes the audio loudness of each transcribed segment to detect when someone is shouting or speaking very softly. Returns decibel (dBFS) levels and classifies each segment by tone. Useful for moderation, call center analysis, lecture reviews, or any scenario where voice tone matters.
Custom thresholds:
How it works:
Audio is analyzed independently from transcription using the original audio file. Unlike the VAD filter (which detects speech vs silence), this measures actual acoustic energy. The original audio is converted to a clean WAV signal (without normalization) and per-segment RMS energy is computed and converted to dBFS relative to full scale.
Threshold guide:
shoutThresholdDb(default-10.0): Segments above this level are classified as shouting. A typical conversation averages around -18 dBFS. Shouting is usually above -10 dBFS.-8.0= Less sensitive (only very loud segments)-12.0= More sensitive (catches raised voices too)
softThresholdDb(default-30.0): Segments below this level are classified as soft/whisper.-25.0= Less sensitive (only whispers)-35.0= More sensitive (includes quiet speech)
Use cases:
- Moderating user-generated audio content
- Detecting agitated speakers in call centers
- Finding whispered or confidential conversation parts
- Analyzing lecture delivery (emphasized vs mumbled sections)
- Content filtering for loud/disturbing audio
Result structure:
Progress Callback
What it does: Allows you to monitor transcription progress in real-time. Useful for long audio files where you want to show a progress bar or status updates to users.
Use cases:
- Showing progress bars in web applications
- Updating job status in queues
- Logging progress for long-running tasks
- Providing user feedback during processing
Timeout Configuration
What it does: Controls how long the transcription process can run before timing out. Useful for long videos or when you need to prevent processes from hanging indefinitely.
Important: For large video files or long recordings, use
->timeout(null)to disable the timeout completely. The default 20-minute timeout for videos may not be sufficient for files larger than 500MB or recordings longer than 30 minutes.
Default timeouts:
- Audio files: 5 minutes (300 seconds)
- Video files: 20 minutes (1200 seconds)
- FFmpeg operations: 10 minutes (600 seconds)
Use cases:
- Processing very long recordings (conferences, lectures)
- Preventing hung processes in production
- Adjusting for slower systems or large models
- Queue job timeout management
Tips:
- Use
timeout(null)for large videos - This is the recommended approach for videos over 20 minutes - Increase timeout for large models (
medium,large) which process slower - Consider chunking for files that consistently timeout
- The default 20-minute timeout for videos may not be enough for long recordings
- Audio files default to 5 minutes, which is usually sufficient
Video Support
What it does: Automatically extracts audio from video files using FFmpeg before transcription. Supports all common video formats (MP4, MKV, AVI, MOV, WebM, etc.).
Supported formats:
- MP4, MKV, AVI, MOV, WMV, FLV, WebM, M4V
- MPEG, MPG, 3GP, 3G2, OGV, TS, MTS, M2TS
Use cases:
- Creating subtitles for videos
- Transcribing video conferences
- Processing YouTube downloads
- Extracting dialogue from movies
- Analyzing video content
Chunking for Large Files
What it does: Automatically splits large audio/video files into smaller chunks for processing. This prevents memory issues and enables processing of very long recordings. Timestamps are automatically adjusted to maintain accuracy across chunks.
When to use:
- Audio/video files larger than 20MB
- Long recordings (>30 minutes)
- Processing on memory-constrained systems
- Video files (automatically enabled)
How it works:
- Calculates optimal chunk duration based on file size
- Splits audio into overlapping segments
- Transcribes each chunk independently
- Merges results with adjusted timestamps
- Returns seamless transcription
Use cases:
- Multi-hour podcasts or lectures
- Full-length movies or documentaries
- All-day conference recordings
- Large video files
- Batch processing of media libraries
Available Models
whisper-php supports all Whisper model sizes. Choose based on your accuracy needs and available resources.
Model Comparison
| Model | Parameters | Size | Speed | Accuracy | Best For |
|---|---|---|---|---|---|
tiny |
39M | ~75 MB | ⚡⚡⚡⚡⚡ Fastest | ⭐⭐ Basic | Real-time, testing |
base |
74M | ~140 MB | ⚡⚡⚡⚡ Very Fast | ⭐⭐⭐ Good | Recommended for most uses |
small |
244M | ~460 MB | ⚡⚡⚡ Fast | ⭐⭐⭐⭐ Very Good | Production, good quality |
medium |
769M | ~1.5 GB | ⚡⚡ Moderate | ⭐⭐⭐⭐⭐ Excellent | High accuracy needs |
large |
1550M | ~3 GB | ⚡ Slow | ⭐⭐⭐⭐⭐ Best | Maximum accuracy, research |
English-Only vs Multilingual
Each model (except large) comes in two variants:
- Multilingual (
tiny,base,small,medium): Supports 99+ languages - English-only (
tiny.en,base.en,small.en,medium.en): Optimized for English, slightly better accuracy
Recommendation: Use .en models if you only transcribe English audio. They're faster and more accurate for English.
Which Model Should You Choose?
For English audio:
- 🥇 Best balanced:
base.en- Great accuracy, fast, small size - 🥈 Higher quality:
small.en- Better accuracy, still reasonably fast - 🥉 Maximum quality:
medium.enorlarge- Best accuracy, slower
For multilingual audio:
- 🥇 Best balanced:
base- Good for most languages - 🥈 Better quality:
small- Recommended for production - 🥉 Maximum quality:
mediumorlarge- Best for critical applications
For specific use cases:
- Real-time transcription:
tinyortiny.en - Mobile/embedded devices:
tinyorbase - Podcasts/interviews (English):
base.enorsmall.en - Podcasts/interviews (multilingual):
baseorsmall - Medical/legal (high accuracy):
medium.enorlarge - Multiple languages with auto-detect:
baseorsmall(default:base) - Testing/development:
tiny.en(fastest downloads)
Real-World Examples
Example 1: Switching Models for Different Accuracy Needs
Example 2: Creating Subtitles for a Video
Example 3: Transcribing Medical Consultation
Example 4: Multilingual Podcast Processing
Example 5: Processing Customer Support Calls
Example 6: Batch Processing with Queue
Working with TranscriptionResult
Logging
You can implement your own logging class by implementing the WhisperPHP\Logger interface:
Testing
Note: Integration tests require Whisper to be set up and will download the tiny model (~75MB) for faster execution.
License
MIT