Skip to main content

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-1
FileTypes
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 both
int
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-hd
string
required
The text to convert to speech (max 4096 characters)
string
required
The voice to use. Options: alloy, echo, fable, onyx, nova, shimmer
string
Audio format. Options: mp3 (default), opus, aac, flac, wav, pcm
float
Speed of the speech (0.25 to 4.0). Default: 1.0

TTS Response

Returns HttpxBinaryResponseContent 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:
  1. Specify language: Improves accuracy if you know the language
  2. Use prompts: Provide context or special terminology
  3. Choose format: Use SRT/VTT for subtitles, JSON for programmatic use
  4. File size: Keep files under 25MB (OpenAI limit)
  5. Audio quality: Better quality audio = better transcription
Text-to-Speech:
  1. Choose right model: Use tts-1-hd for higher quality
  2. Select appropriate voice: Test different voices for your use case
  3. Break up long text: Split into chunks for better processing
  4. Control speed: Adjust for different use cases (audiobooks vs announcements)
  5. 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-hd model for better quality