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

build_prefix(tokenizer, text, num_audio_codebook)

Everything before the target canvas.

build_style_text(language, instruct, ...)

The control preamble.

combine_text(text[, ref_text])

Join the reference transcript to the target text and normalise spacing.

resolve_instruct(instruct[, text])

Validate a voice-design instruct string, raising ValueError on a bad one.

resolve_language(language)

Map a language name to the id the model was trained on.

tokenize_with_nonverbal_tags(text, tokenizer)

Tokenize to [1, N], splitting non-verbal tags into their own calls.

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 all C codebook rows; the reference audio span is genuinely per-codebook and is the only part of the prefix flagged as audio.

has_reference is separate from ref_audio_tokens on purpose. The style span is built on the data worker, where the reference has not been encoded yet, so the tokens are None there 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.

Parameters:
  • text (str)

  • num_audio_codebook (int)

  • language (str | None)

  • instruct (str | None)

  • ref_text (str | None)

  • ref_audio_tokens (Tensor | None)

  • has_reference (bool | None)

  • denoise (bool)

Return type:

tuple[Tensor, Tensor]

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 string None rather than an omitted span — the model was trained with the span always present.

Parameters:
  • language (str | None)

  • instruct (str | None)

  • denoise (bool)

  • has_reference (bool)

Return type:

str

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.

Parameters:
  • text (str)

  • ref_text (str | None)

Return type:

str

mstar.model.omnivoice.components.text.resolve_instruct(instruct, text='')[source]#

Validate a voice-design instruct string, raising ValueError on 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.

text picks the vocabulary the way the reference does, by looking for a CJK character in the text being spoken rather than by the language argument: a Chinese instruct is rejected against the English list.

Parameters:
  • instruct (str | None)

  • text (str)

Return type:

str | None

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 to None. 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 public lang_map tables, so a language added upstream needs no change here.

Parameters:

language (str | None)

Return type:

str | None

mstar.model.omnivoice.components.text.tokenize_with_nonverbal_tags(text, tokenizer)[source]#

Tokenize to [1, N], splitting non-verbal tags into their own calls.

Parameters:

text (str)

Return type:

Tensor