Skip to main content

Overview

ASRInferencePipeline provides a high-level interface for performing speech-to-text transcription using Omnilingual ASR models. It handles audio preprocessing, model inference, and beam search decoding.

Constructor

str | None
required
Model card name to load from the hub (e.g., "omniASR_LLM_7B"). Mutually exclusive with model and tokenizer parameters. Recommended for inference.
Wav2Vec2LlamaModel | Wav2Vec2AsrModel | None
Pre-loaded model instance. Mutually exclusive with model_card. Must be provided together with tokenizer.
Tokenizer | None
Pre-loaded tokenizer instance. Mutually exclusive with model_card. Must be provided together with model.
str | torch.device | None
Device to run inference on. Defaults to "cuda" if available, otherwise "cpu".
torch.dtype
default:"torch.bfloat16"
Data type for model inference.
Wav2Vec2LlamaBeamSearchConfig | None
Optional beam search configuration. If not provided, uses default configuration with nbest=1 and length_norm=False.

Example

Methods

transcribe

Transcribes audio inputs into text with automatic preprocessing (decoding, resampling to 16kHz, converting to mono, normalizing).
AudioInput
required
Audio input in one of the following formats:
  • List[Path | str]: Audio file paths
  • List[bytes]: Raw audio data
  • List[np.ndarray]: Audio data as uint8 numpy arrays
  • List[dict]: Pre-decoded audio with 'waveform' and 'sample_rate' keys
List[str | None] | None
Language codes for input audios (e.g., 'eng_Latn', 'fra_Latn'). Must be the same length as inp. Ignored for CTC models. For LLM models, providing language codes improves transcription quality.
int
default:"2"
Number of audio samples to process in each batch.
List[str]
Transcribed texts for each input audio.

Example

Maximum audio length is capped at 40 seconds per sample. For longer audio, use the streaming model variant.

transcribe_with_context

Transcribes audio using zero-shot learning with context examples. Only works with the omniASR_LLM_7B_ZS model.
AudioInput
required
Audio input (same formats as transcribe method).
List[List[ContextExample]]
required
A list of context examples for each input audio. Each inner list contains audio-text pairs demonstrating the transcription style/language. At least one context example is required per input. If fewer than 10 examples are provided, they are replicated. If more than 10 are provided, only the first 10 are used.
int
default:"1"
Number of audio samples to process in each batch.
List[str]
Transcribed texts for each input audio.

Example

This method raises NotImplementedError if used with non-zero-shot models. Use the regular transcribe() method instead.

Raises

  • ValueError: If both model_card and model/tokenizer are provided, or if only one of model/tokenizer is provided.
  • ValueError: If audio exceeds 40 seconds (non-streaming models).
  • NotImplementedError: If transcribe_with_context() is called on non-zero-shot models, or if transcribe() is called on zero-shot models.

Source Reference

See implementation at src/omnilingual_asr/models/inference/pipeline.py:148