Overview
LiteLLM provides unified interfaces for audio transcription (speech-to-text) and text-to-speech (TTS) across multiple providers including OpenAI Whisper, Azure, and more.Audio Transcription
Basic Usage
Function Signature
Transcription Parameters
string
required
The transcription model to use. Example:
whisper-1FileTypes
required
The audio file to transcribe. Supported formats: mp3, mp4, mpeg, mpga, m4a, wav, webm
string
Language of the audio in ISO-639-1 format (e.g., “en”, “fr”, “es”)
string
Optional text to guide the model’s style or continue a previous segment
string
Format of the transcript output. Options:
"json", "text", "srt", "verbose_json", "vtt"List[str]
Timestamp granularities. Options:
["word"], ["segment"], or bothint
Sampling temperature (0 to 1). Higher values make output more random.
Transcription Response
Transcription Examples
Basic Transcription
Transcription with Language
Different Response Formats
Async Transcription
Multiple Files Concurrently
Text-to-Speech
Basic Usage
Function Signature
TTS Parameters
string
required
The TTS model to use. Examples:
tts-1, tts-1-hdstring
required
The text to convert to speech (max 4096 characters)
string
required
The voice to use. Options:
alloy, echo, fable, onyx, nova, shimmerstring
Audio format. Options:
mp3 (default), opus, aac, flac, wav, pcmfloat
Speed of the speech (0.25 to 4.0). Default: 1.0
TTS Response
ReturnsHttpxBinaryResponseContent with audio data:
TTS Examples
Basic Text-to-Speech
Different Voices
High Quality Audio
Adjust Speech Speed
Different Audio Formats
Async Text-to-Speech
Generate Multiple Audio Files
Combined Use Cases
Voice Message Transcription
Audio Book Generation
Language Learning Assistant
Meeting Transcription and Summary
Error Handling
Best Practices
Transcription:
- Specify language: Improves accuracy if you know the language
- Use prompts: Provide context or special terminology
- Choose format: Use SRT/VTT for subtitles, JSON for programmatic use
- File size: Keep files under 25MB (OpenAI limit)
- Audio quality: Better quality audio = better transcription
- Choose right model: Use
tts-1-hdfor higher quality - Select appropriate voice: Test different voices for your use case
- Break up long text: Split into chunks for better processing
- Control speed: Adjust for different use cases (audiobooks vs announcements)
- Format selection: Use MP3 for web, WAV/FLAC for high quality
Troubleshooting
Transcription Issues
- Low accuracy: Specify language, improve audio quality
- File too large: Split audio into smaller chunks
- Timeout: Increase timeout parameter for long files
TTS Issues
- Text too long: Split into chunks of less than 4096 characters
- Pronunciation: Use phonetic spelling in input
- Quality: Use
tts-1-hdmodel for better quality