本页还没有译文
本页 43 段还没译成Español,下面显示的是英文原文。Speech-to-Text (Transcription/Translation) Support
还没翻译译自英文(docs.vllm.ai)本页 43 段都还没译
Speech-to-Text (Transcription/Translation) Support
This document walks you through the steps to add support for speech-to-text (ASR) models to vLLM’s transcription and translation APIs by implementing SupportsTranscription. Please refer to the supported models for further guidance.
Update the base vLLM model
It is assumed you have already implemented your model in vLLM according to the basic model guide. Extend your model with the SupportsTranscription interface and implement the following class attributes and methods.
supported_languages and supports_transcription_only
Declare supported languages and capabilities:
- The
supported_languagesmapping is validated at init time. - Set
supports_transcription_only=Trueif the model should not serve text generation (eg Whisper).
Provide an ASR configuration via get_speech_to_text_config.
This is for controlling general behavior of the API when serving your model:
See Audio preprocessing and chunking for what each field controls.
Implement the prompt construction via get_generation_prompt. The server builds a SpeechToTextParams object that bundles the resampled waveform, task parameters, and request-specific options. Your model receives this single object and returns a valid PromptType. There are two common patterns:
Multimodal LLM with audio embeddings (e.g., Voxtral, Gemma3n)
Return a dict containing multi_modal_data with the audio, and either a prompt string or prompt_token_ids:
Encoder–decoder audio-only (e.g., Whisper)
Return a dict with separate encoder_prompt and decoder_prompt entries:
validate_language (optional)
Language validation via validate_language
If your model requires a language and you want a default, override this method (see Whisper):
get_num_audio_tokens (optional)
Token accounting for streaming via get_num_audio_tokens
Provide a fast duration→token estimate to improve streaming usage statistics:
Audio preprocessing and chunking
The API server takes care of basic audio I/O and optional chunking before building prompts:
- Resampling: Input audio is resampled to
SpeechToTextConfig.sample_rateusingAudioResampler. - Chunking: If
SpeechToTextConfig.allow_audio_chunkingis True and the duration exceedsmax_audio_clip_s, the server splits the audio into chunks and generates a prompt per chunk. There is no overlap between chunks, overlap_chunk_second controls the size of the search window used to find the split point. - Energy-aware splitting: When
min_energy_split_window_sizeis set, the server finds low-energy regions to minimize cutting within words.
Relevant server logic:
Exposing tasks automatically
vLLM automatically advertises transcription support if your model implements the interface:
if supports_transcription(model):
if model.supports_transcription_only:
return ["transcription"]
supported_tasks.append("transcription")When enabled, the server initializes the transcription and translation handlers:
state.openai_serving_transcription = OpenAIServingTranscription(...) if "transcription" in supported_tasks else None
state.openai_serving_translation = OpenAIServingTranslation(...) if "transcription" in supported_tasks else NoneNo extra registration is required beyond having your model class available via the model registry and implementing SupportsTranscription.
Examples in-tree
- Whisper encoder–decoder (audio-only): vllm/model_executor/models/whisper.py
- Voxtral decoder-only (audio embeddings + LLM): vllm/model_executor/models/voxtral.py. Make sure to have installed
mistral-common[audio]. - Gemma3n decoder-only with fixed instruction prompt: vllm/model_executor/models/gemma3n_mm.py
- Qwen3-Omni multimodal with audio embeddings: vllm/model_executor/models/qwen3_omni_moe_thinker.py
Test with the API
Once your model implements SupportsTranscription, you can test the endpoints (API mimics OpenAI):
-
Transcription (ASR):
curl -s -X POST \ -H "Authorization: Bearer $VLLM_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F "file=@/path/to/audio.wav" \ -F "model=$MODEL_ID" \ http://localhost:8000/v1/audio/transcriptions -
Translation (source → English unless otherwise supported):
curl -s -X POST \ -H "Authorization: Bearer $VLLM_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F "file=@/path/to/audio.wav" \ -F "model=$MODEL_ID" \ http://localhost:8000/v1/audio/translations
Or check out more examples in examples/speech_to_text.
Note
- If your model handles chunking internally (e.g., via its processor or encoder), set
min_energy_split_window_size=Nonein the returnedSpeechToTextConfigto disable server-side chunking. - Implementing
get_num_audio_tokensimproves accuracy of streaming usage metrics (prompt_tokens) without an extra forward pass. - For multilingual behavior, keep
supported_languagesaligned with actual model capabilities.