vllm_omni.utils.forced_aligner ¶
Shared forced aligner for streaming TTS word timestamps.
Hosts one lazy-loaded, in-process pooling vllm.LLM shared by the TTS frontend. llm.encode is sync/blocking, so :func:align runs it in asyncio.to_thread, serialized on a lock since the offline LLM is not thread-safe. See :func:align for the return-value contract.
ForcedAlignerConfig dataclass ¶
ForcedAlignerLoadError ¶
Bases: RuntimeError
The aligner model/config could not be loaded (permanent until restart).
Distinguished from a per-request alignment failure so the streaming layer can report a clear reason once rather than degrading every request to timestamps: null.
WordTimestamp dataclass ¶
align async ¶
align(
*,
audio: bytes,
text: str,
sample_rate: int,
config: ForcedAlignerConfig,
language: str | None = None,
) -> list[WordTimestamp] | None
Run one forced-alignment pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio | bytes | Signed-int16 little-endian mono PCM bytes. | required |
text | str | Ground-truth text whose words to align. | required |
sample_rate | int | Sample rate of | required |
config | ForcedAlignerConfig | Aligner config (same instance for every call across the server's lifetime; reload requires a server restart). | required |
language | str | None | Optional language hint for word segmentation. | None |
Returns:
| Type | Description |
|---|---|
list[WordTimestamp] | None | List of :class: |
list[WordTimestamp] | None | silence / no aligned tokens), |
list[WordTimestamp] | None | failure (decode error). |
Raises:
| Type | Description |
|---|---|
ForcedAlignerLoadError | the model/config could not be loaded. This is permanent until restart, so callers surface it once instead of degrading every request to |
build_forced_aligner_config ¶
build_forced_aligner_config(
args: Any,
) -> ForcedAlignerConfig | None
Build a config from CLI args, or None when the feature is off.
Precedence (lowest to highest): the packaged default YAML (:data:_DEFAULT_CONFIG_PATH, Qwen deploy defaults) -> a user YAML passed via --forced-aligner-config -> the --forced-aligner model path. The feature is off (returns None) unless a model resolves from this chain. Per-field overrides such as gpu_memory_utilization live in the YAML.