mstar.model.omnivoice.components.text#
Prompt construction: style tokens, text tokens, and the canvas prefix.
Ported from OmniVoice._prepare_inference_inputs and its helpers rather than
imported, because these are private to the reference package and decide parity:
a drift in whitespace handling or in how a non-verbal tag is split changes the
token ids the backbone sees. Pinned to the behaviour of OmniVoice as of the
k2-fsa/OmniVoice checkpoint; the parity test is what catches upstream drift.
The prefix these build is fixed for a request’s whole diffusion loop, so it is computed once on the data worker and persisted, not rebuilt per step.
Functions
|
Everything before the target canvas. |
|
The control preamble. |
|
Join the reference transcript to the target text and normalise spacing. |
|
Validate a voice-design instruct string, raising |
|
Map a language name to the id the model was trained on. |
|
Tokenize to |
- mstar.model.omnivoice.components.text.build_prefix(tokenizer, text, num_audio_codebook, language=None, instruct=None, ref_text=None, ref_audio_tokens=None, has_reference=None, denoise=True)[source]#
Everything before the target canvas.
Returns
(prefix_ids [C, N], prefix_audio_mask [N]). Text spans repeat one row of ids across allCcodebook rows; the reference audio span is genuinely per-codebook and is the only part of the prefix flagged as audio.has_referenceis separate fromref_audio_tokenson purpose. The style span is built on the data worker, where the reference has not been encoded yet, so the tokens areNonethere even for a cloning request; inferring the flag from them would drop<|denoise|>from every clone. Defaults to the tokens being present, for callers that have both.
- mstar.model.omnivoice.components.text.build_style_text(language, instruct, denoise, has_reference)[source]#
The control preamble.
<|denoise|>only applies when there is reference audio to denoise, so the flag alone does not add it. Absent language or instruction are the literal stringNonerather than an omitted span — the model was trained with the span always present.
- mstar.model.omnivoice.components.text.combine_text(text, ref_text=None)[source]#
Join the reference transcript to the target text and normalise spacing.
Voice cloning conditions on transcript and audio, so the reference transcript is prepended to the target text and the whole thing is read as one utterance.
- mstar.model.omnivoice.components.text.resolve_instruct(instruct, text='')[source]#
Validate a voice-design instruct string, raising
ValueErroron a bad one.Delegates to the reference’s validator rather than re-porting it: the vocabulary is long (gender, age, pitch, style, accent, and the Chinese dialect list) and it silently repairs separator mistakes, so a second copy would drift from the checkpoint it has to match.
textpicks the vocabulary the way the reference does, by looking for a CJK character in the text being spoken rather than by thelanguageargument: a Chinese instruct is rejected against the English list.
- mstar.model.omnivoice.components.text.resolve_language(language)[source]#
Map a language name to the id the model was trained on.
"English"becomes"en", an id passes through, anything else warns and resolves toNone. The style span is a token, not prose: a raw"Chinese"reaching the backbone produces background noise rather than Chinese. Reads the reference’s own publiclang_maptables, so a language added upstream needs no change here.