[TTS][New Model] support bosonai/higgs-audio-v3-tts-4b (#4169)

Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com>
Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
Co-authored-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
Yuekai ZhangandYueqian Lin authored and GitHub committed 2026-06-06 15:59:12 +00:00
1 parent 963ba1ab7a
commit 82e74ce972
22 files changed
+4295

No files matched your search

@@ -115,6 +115,54 @@ class OpenAICreateSpeechRequest(BaseModel):
raise ValueError("'speaker_embedding' values must be finite (no NaN or Inf)")
return v
@model_validator(mode="before")
@classmethod
def normalize_references_alias(cls, data):
"""Map the BosonAI Higgs Audio v3 cookbook ``references`` array onto ``ref_audio`` / ``ref_text``.
Upstream Higgs Audio v3 examples and the boson.ai cookbook send voice
clones as::
{"references": [{"audio_path": str, "text": str}]}
vllm-omni's existing convention is ``ref_audio`` + ``ref_text``.
Without this alias pydantic silently drops the unknown ``references``
field and the request falls through to zero-shot synthesis with no
error, which is hard to debug from the client side. The normalizer
translates a single reference and rejects multi-reference payloads
(vllm-omni does not yet support multi-shot voice clone) or conflicts
with the explicit ``ref_audio`` / ``ref_text`` fields.
"""
if not isinstance(data, dict):
return data
refs = data.get("references")
if refs is None:
return data
if not isinstance(refs, list) or len(refs) == 0:
raise ValueError("'references' must be a non-empty array of {audio_path, text} objects")
if len(refs) > 1:
raise ValueError("'references' only supports a single reference; multi-shot voice clone is not supported")
first = refs[0]
if not isinstance(first, dict):
raise ValueError("'references[0]' must be an object with 'audio_path' and optional 'text'")
audio_path = first.get("audio_path")
if not isinstance(audio_path, str) or not audio_path:
raise ValueError(
"'references[0].audio_path' is required and must be a string (URL, data: URI, or file path)"
)
existing_ref_audio = data.get("ref_audio")
if existing_ref_audio and existing_ref_audio != audio_path:
raise ValueError("'references' and 'ref_audio' are mutually exclusive")
data["ref_audio"] = audio_path
text = first.get("text")
if isinstance(text, str) and text.strip():
existing_ref_text = data.get("ref_text")
if existing_ref_text and existing_ref_text != text:
raise ValueError("'references[0].text' and 'ref_text' conflict; supply only one")
data["ref_text"] = text
data.pop("references", None)
return data
@model_validator(mode="before")
@classmethod
def reject_higgs_audio_v2_unsupported_aliases(cls, data):
@@ -76,6 +76,7 @@ _MING_TTS_MODEL_STAGES = {"ming_tts"}
_MOSS_TTS_MODEL_STAGES = {"moss_tts_nano"}
_MOSS_TTS_FULL_MODEL_STAGES = {"moss_tts", "moss_tts_codec"}
_HIGGS_AUDIO_V2_TTS_MODEL_STAGES = {"higgs_audio_v2"}
_HIGGS_AUDIO_V3_TTS_MODEL_STAGES = {"higgs_audio_v3"}
_GLM_TTS_MODEL_STAGES = {"glm_tts"}
_TTS_MODEL_STAGES: set[str] = (
_VOXTRAL_TTS_MODEL_STAGES
@@ -84,6 +85,7 @@ _TTS_MODEL_STAGES: set[str] = (
| _COSYVOICE3_TTS_MODEL_STAGES
| _OMNIVOICE_TTS_MODEL_STAGES
| _HIGGS_AUDIO_V2_TTS_MODEL_STAGES
| _HIGGS_AUDIO_V3_TTS_MODEL_STAGES
| _COVO_AUDIO_MODEL_STAGES
| _VOXCPM2_TTS_MODEL_STAGES
| _MING_TTS_MODEL_STAGES
@@ -98,6 +100,7 @@ _SAMPLING_MAX_TOKENS_TTS_MODEL_TYPES = {
"cosyvoice3",
"voxcpm2",
"higgs_audio_v2",
"higgs_audio_v3",
}
_TTS_LANGUAGES: set[str] = {
"Auto",
@@ -594,6 +597,8 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
return "moss_tts"
if model_stage in _HIGGS_AUDIO_V2_TTS_MODEL_STAGES:
return "higgs_audio_v2"
if model_stage in _HIGGS_AUDIO_V3_TTS_MODEL_STAGES:
return "higgs_audio_v3"
if model_stage in _GLM_TTS_MODEL_STAGES:
return "glm_tts"
return None
@@ -934,6 +939,7 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
"moss_tts_nano",
"glm_tts",
"higgs_audio_v2",
"higgs_audio_v3",
):
label = {
"cosyvoice3": "CosyVoice3",
@@ -941,6 +947,7 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
"omnivoice": "OmniVoice",
"moss_tts_nano": "MOSS-TTS-Nano",
"higgs_audio_v2": "Higgs-Audio V2",
"higgs_audio_v3": "Higgs-Audio V3",
"glm_tts": "GLM-TTS",
}.get(self._tts_model_type, self._tts_model_type)
return (
@@ -1896,6 +1903,84 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
self._higgs_audio_v2_processor = processor
return processor
# ---- higgs-audio v3 ----
def _validate_higgs_audio_v3_request(self, request: OpenAICreateSpeechRequest) -> str | None:
"""Validate higgs_audio_v3 request parameters."""
if not request.input or not request.input.strip():
return "higgs_audio_v3: input text cannot be empty"
if request.ref_audio is not None and not request.ref_text:
# Voice clone ref_text is optional for v3 (improves fidelity but not required)
pass
if request.max_new_tokens is not None:
if request.max_new_tokens < _TTS_MAX_NEW_TOKENS_MIN:
return f"max_new_tokens must be at least {_TTS_MAX_NEW_TOKENS_MIN}"
return None
async def _build_higgs_audio_v3_params(self, request: OpenAICreateSpeechRequest):
"""Build prompt_token_ids for higgs_audio_v3.
Plain-text path: builds ``[tts, text, tokens, audio]``.
Voice-clone path: encodes reference audio, applies delay pattern,
builds ``[tts, (ref_text, tokens,) ref_audio, -100xN, text, tokens, audio]``.
"""
adapter = await self._resolve_higgs_audio_v3_adapter()
if request.ref_audio is None:
prompt_ids = adapter.build_prompt(request.input)
return tokens_input(prompt_token_ids=prompt_ids)
# Voice clone
from vllm_omni.model_executor.models.higgs_audio_v3.higgs_audio_v3_tokenizer import (
apply_delay_pattern,
encode_reference_audio,
)
wav_list, sr = await self._resolve_ref_audio(request.ref_audio)
wav = np.asarray(wav_list, dtype=np.float32)
ref_codes_raw = await asyncio.to_thread(encode_reference_audio, wav, int(sr))
ref_codes_delayed = apply_delay_pattern(ref_codes_raw)
prompt_ids = adapter.build_prompt(
request.input,
num_ref_tokens=int(ref_codes_delayed.shape[0]),
reference_text=request.ref_text or None,
)
prompt = tokens_input(prompt_token_ids=prompt_ids)
import torch
prompt["additional_information"] = {
"audio_input_ids": ref_codes_delayed.to(torch.long),
"audio_input_ids_mask": torch.ones(ref_codes_delayed.shape[0], dtype=torch.bool),
}
return prompt
async def _resolve_higgs_audio_v3_adapter(self):
"""Lazy-load the tokenizer adapter for higgs_audio_v3."""
cached = getattr(self, "_higgs_audio_v3_adapter", None)
if cached is not None:
return cached
from transformers import AutoTokenizer
from vllm_omni.model_executor.models.higgs_audio_v3.higgs_audio_v3_tokenizer import (
HiggsAudioV3TokenizerAdapter,
)
model_path = None
for stage in self.engine_client.stage_configs:
model_path = getattr(getattr(stage, "engine_args", None), "model", None)
if model_path:
break
if model_path is None:
model_path = getattr(self.engine_client, "model", None)
if model_path is None:
raise RuntimeError("higgs_audio_v3 serving could not resolve model path")
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
adapter = HiggsAudioV3TokenizerAdapter(tokenizer)
self._higgs_audio_v3_adapter = adapter
return adapter
def _validate_fish_tts_request(self, request: OpenAICreateSpeechRequest) -> str | None:
"""Validate Fish Speech request parameters. Returns error message or None."""
if not request.input or not request.input.strip():
@@ -2796,6 +2881,15 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
additional["voice_name"] = voice_lower
additional["voice_created_at"] = self._voice_created_at(voice_lower)
tts_params = {}
elif self._tts_model_type == "higgs_audio_v3":
err = self._apply_uploaded_speaker(request)
if err:
raise ValueError(err)
validation_error = self._validate_higgs_audio_v3_request(request)
if validation_error:
raise ValueError(validation_error)
prompt = await self._build_higgs_audio_v3_params(request)
tts_params = {}
elif self._tts_model_type == "voxcpm2":
# voxcpm2 doesn't use `_apply_uploaded_speaker` because the prompt builder needs the
# raw waveform tuple for prefill-length accounting, not a base64 data URL.