Skip to main content

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_languages mapping is validated at init time.
  • Set supports_transcription_only=True if 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_rate using AudioResampler.
  • Chunking: If SpeechToTextConfig.allow_audio_chunking is True and the duration exceeds max_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_size is 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 None

No extra registration is required beyond having your model class available via the model registry and implementing SupportsTranscription.

Examples in-tree

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=None in the returned SpeechToTextConfig to disable server-side chunking.
  • Implementing get_num_audio_tokens improves accuracy of streaming usage metrics (prompt_tokens) without an extra forward pass.
  • For multilingual behavior, keep supported_languages aligned with actual model capabilities.