Skip to main content

Class Definition

Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:44-61
Do not instantiate directly. Use from_pretrained() instead.

Methods

from_pretrained()

Load a pretrained tokenizer model with HuggingFace-style initialization.
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:63-99

Parameters

str
required
HuggingFace model repository ID or local directory path.Examples:
  • "Qwen/Qwen3-TTS-Tokenizer-25Hz"
  • "Qwen/Qwen3-TTS-Tokenizer-12Hz"
  • "/path/to/local/model"
Any
Additional keyword arguments forwarded to AutoModel.from_pretrained().Common options:
  • device_map: Device placement (e.g., "cuda:0", "cpu", "auto")
  • torch_dtype: Model precision (e.g., torch.bfloat16, torch.float16)
  • attn_implementation: Attention implementation (e.g., "eager", "flash_attention_2")

Returns

Qwen3TTSTokenizer
Initialized tokenizer instance with loaded model, feature extractor, and config.

Example

load_audio()

Load audio from a file path or base64 string and resample to target sample rate.
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:122-158

Parameters

str
required
Audio source:
  • File path to WAV file
  • HTTP/HTTPS URL to audio file
  • Base64 encoded audio string (raw or data URL format)
int
required
Target sampling rate in Hz for resampling.

Returns

np.ndarray
1-D float32 numpy array containing the resampled audio waveform at target_sr.

Example

Utility Methods

get_model_type()

Get the underlying tokenizer model type.
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:367-375
Returns: "qwen3_tts_tokenizer_25hz" or "qwen3_tts_tokenizer_12hz"

get_input_sample_rate()

Get the expected input sample rate for encoding.
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:377-384
Returns: Input sample rate in Hz

get_output_sample_rate()

Get the output sample rate for decoded waveforms.
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:386-393
Returns: Output sample rate in Hz

get_encode_downsample_rate()

Get the encoder downsample rate (waveform samples per code step).
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:395-402
Returns: Encode downsample rate

get_decode_upsample_rate()

Get the decoder upsample rate (waveform samples per code step).
Defined in qwen_tts/inference/qwen3_tts_tokenizer.py:404-411
Returns: Decode upsample rate

AudioInput Type

The tokenizer accepts the following input types (defined in qwen_tts/inference/qwen3_tts_tokenizer.py:36-41):