Skip to main content

ModelFiles

Struct ModelFiles 

Source
pub struct ModelFiles {
    pub config: Option<ModelAsset>,
    pub tokenizer: Option<ModelAsset>,
    pub weights: Vec<ModelAsset>,
    pub voices_dir: Option<ModelAssetDir>,
    pub speech_tokenizer_weights: Vec<ModelAsset>,
    pub speech_tokenizer_config: Option<ModelAsset>,
    pub generation_config: Option<ModelAsset>,
    pub preprocessor_config: Option<ModelAsset>,
}
Expand description

Resolved model assets for loading.

Each model type requires a specific set of files. You can provide them individually using the builder methods on TtsConfig, set TtsConfig::model_path to a directory that contains all of them, or rely on automatic HuggingFace Hub download (if the download feature is enabled).

§File resolution order (per file)

  1. Explicit path — set via with_*_file() / with_*_dir() on TtsConfig. Use this when your project has its own download manager (e.g. flow-like hash-based local caching).
  2. Auto-discovery — if model_path is set, the library looks for well-known filenames inside that directory.
  3. HuggingFace Hub download — if the download feature is enabled and the file is still missing, it is fetched from the Hub. This is the convenient fallback for quick prototyping.

Fields§

§config: Option<ModelAsset>

Path to config.json — model architecture configuration.

Expected format: JSON object describing the neural-network hyperparameters (hidden size, number of layers, vocab size, …). This is the standard HuggingFace config.json format. Each backend stores its architecture metadata here, such as transformer dimensions, tokenizer sizes, sample rates, or auxiliary decoder configuration.

§tokenizer: Option<ModelAsset>

Path to tokenizer.json — BPE text tokenizer definition.

Expected format: HuggingFace Tokenizers self-contained JSON file. Contains the full vocabulary, merge rules, special tokens, and pre/post-processing steps. No separate vocab.json or merges.txt required when this file is present.

Used by both models to convert input text into token IDs before feeding them to the transformer backbone.

§weights: Vec<ModelAsset>

Paths to model weight files (.safetensors).

Expected format: One or more SafeTensors files containing the neural-network parameters.

  • Single filemodel.safetensors (for models < ~5 GB).
  • Shardedmodel-00001-of-00004.safetensors, … When sharded, the library also expects model.safetensors.index.json in the same directory (auto-discovered or downloaded).
  • Other formats — some backends use consolidated.safetensors or .pth files instead of the standard filename.
§voices_dir: Option<ModelAssetDir>

Path to a voice asset directory for backends that ship preset voices.

Supported layouts include:

voices/                ← Kokoro preset voices (`*.pt`)
voice_embedding/       ← Voxtral preset voices (`*.pt`)

The exact file format depends on the backend.

§speech_tokenizer_weights: Vec<ModelAsset>

Paths to the speech/audio tokenizer decoder weight files.

Expected format: SafeTensors files for the auxiliary decoder used by models that emit discrete audio codec tokens.

Contains:

  • Residual VQ codebooks (16 groups × 2048 codes × dim)

  • Pre-conv + pre-transformer layers

  • Upsampling layers (transposed convolutions + SnakeBeta)

  • Final decoder convolution

  • Qwen3-TTS uses the separate Qwen/Qwen3-TTS-Tokenizer-12Hz repository.

  • OmniVoice uses the audio_tokenizer/ subdirectory inside the main model snapshot.

§speech_tokenizer_config: Option<ModelAsset>

Path to config.json of the speech/audio tokenizer.

Expected format: JSON config for the speech tokenizer decoder model, including codebook dimensions, upsampling ratios, and activation parameters.

If not provided, will be auto-discovered from a nested audio_tokenizer/ directory or downloaded from HuggingFace.

§generation_config: Option<ModelAsset>

Path to generation_config.json (optional).

Expected format: Standard HuggingFace generation configuration with fields like max_new_tokens, top_p, temperature, do_sample, repetition_penalty, etc.

If not provided, sensible per-model defaults are used.

§preprocessor_config: Option<ModelAsset>

Path to preprocessor_config.json (optional).

Used by backends such as VibeVoice that publish prompt-building and audio-normalization defaults separately from config.json.

Implementations§

Source§

impl ModelFiles

Source

pub fn fill_from_directory(&mut self, dir: &Path)

Scan a directory for well-known model files and fill any that are still None / empty.

Source

pub fn fill_from_asset_bundle(&mut self, bundle: &ModelAssetBundle)

Scan an in-memory asset bundle for well-known model files.

Source

pub fn load_safetensors_vb( assets: &[ModelAsset], dtype: DType, device: &Device, ) -> Result<VarBuilder<'static>, TtsError>

Build a VarBuilder by reading safetensors files fully into memory.

This is the safe alternative to VarBuilder::from_mmaped_safetensors which requires unsafe due to memory-mapping. The trade-off is a brief peak in memory while the raw bytes and parsed tensors coexist, but for model loading this is negligible compared to the final tensor footprint.

Source

pub fn fill_from_hf( &mut self, model_id: &str, model_type: ModelType, bearer_token: Option<&str>, ) -> Result<(), TtsError>

Download missing files from HuggingFace Hub.

model_type determines which files are required.

Source

pub fn validate(&self, model_type: ModelType) -> Result<(), TtsError>

Check whether all required files for the given model type are present.

Source

pub fn missing_files(&self, model_type: ModelType) -> Vec<&'static str>

Return the list of files that are required but not yet set.

Trait Implementations§

Source§

impl Clone for ModelFiles

Source§

fn clone(&self) -> ModelFiles

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelFiles

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelFiles

Source§

fn default() -> ModelFiles

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,