### Install LuxTTS Dependencies Source: https://github.com/ysharma3501/luxtts/blob/master/README.md Commands to clone the repository and install the necessary Python dependencies for LuxTTS. ```bash git clone https://github.com/ysharma3501/LuxTTS.git cd LuxTTS pip install -r requirements.txt ``` -------------------------------- ### Process Audio with Utility Functions Source: https://context7.com/ysharma3501/luxtts/llms.txt Provides examples for common audio tasks such as RMS normalization, silence removal, cross-fade concatenation, and text punctuation handling for improved prosody. ```python from zipvoice.utils.infer import (rms_norm, remove_silence, cross_fade_concat, load_prompt_wav, add_punctuation, chunk_tokens_punctuation) import torch waveform = torch.randn(1, 48000) normalized_wav, original_rms = rms_norm(waveform, target_rms=0.1) prompt_wav = load_prompt_wav('audio.wav', sampling_rate=24000) cleaned_audio = remove_silence(audio=waveform, sampling_rate=24000, only_edge=False, trail_sil=100) chunks = [torch.randn(1, 24000), torch.randn(1, 24000), torch.randn(1, 24000)] combined = cross_fade_concat(chunks, fade_duration=0.1, sample_rate=24000) text = add_punctuation("Hello world") tokens = ['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '.'] chunks = chunk_tokens_punctuation(tokens, max_tokens=100) ``` -------------------------------- ### Perform Speech Inference Source: https://github.com/ysharma3501/luxtts/blob/master/README.md Basic and advanced inference examples for generating speech from text using a reference audio prompt. ```python import soundfile as sf from IPython.display import Audio text = "Hey, what's up? I'm feeling really great if you ask me honestly!" prompt_audio = 'audio_file.wav' # Encode and generate encoded_prompt = lux_tts.encode_prompt(prompt_audio, rms=0.01) final_wav = lux_tts.generate_speech(text, encoded_prompt, num_steps=4) # Save and display final_wav = final_wav.numpy().squeeze() sf.write('output.wav', final_wav, 48000) if display is not None: display(Audio(final_wav, rate=48000)) ``` ```python import soundfile as sf from IPython.display import Audio text = "Hey, what's up? I'm feeling really great if you ask me honestly!" prompt_audio = 'audio_file.wav' # Advanced sampling parameters encoded_prompt = lux_tts.encode_prompt(prompt_audio, duration=5, rms=0.01) final_wav = lux_tts.generate_speech(text, encoded_prompt, num_steps=4, t_shift=0.9, speed=1.0, return_smooth=False) final_wav = final_wav.numpy().squeeze() sf.write('output.wav', final_wav, 48000) if display is not None: display(Audio(final_wav, rate=48000)) ``` -------------------------------- ### Load LuxTTS Models and Components Source: https://context7.com/ysharma3501/luxtts/llms.txt Shows how to load model components for GPU or CPU inference, access configuration settings, and process reference audio for generation. ```python from zipvoice.modeling_utils import load_models_gpu, load_models_cpu, LuxTTSConfig, generate, process_audio model, feature_extractor, vocos, tokenizer, transcriber = load_models_gpu(model_path=None, device='cuda') config = LuxTTSConfig() print(f"Tokenizer type: {config.tokenizer}") prompt_tokens, prompt_features_lens, prompt_features, prompt_rms = process_audio( audio='reference.wav', transcriber=transcriber, tokenizer=tokenizer, feature_extractor=feature_extractor, device='cuda', target_rms=0.1, duration=5, feat_scale=0.1 ) ``` -------------------------------- ### LuxTTS Class Initialization Source: https://context7.com/ysharma3501/luxtts/llms.txt Demonstrates how to load the LuxTTS model for inference on different hardware devices (CUDA, CPU, MPS) and with specified thread counts. ```APIDOC ## LuxTTS Class Initialization ### Description Initializes the LuxTTS model, handling automatic device detection and loading from Hugging Face Hub. Supports CUDA, Apple Silicon (MPS), and CPU inference. ### Method `LuxTTS(model_name: str, device: str = 'auto', threads: int = 0)` ### Parameters #### Path Parameters None #### Query Parameters - **model_name** (str) - Required - The name of the LuxTTS model on Hugging Face Hub (e.g., 'YatharthS/LuxTTS'). - **device** (str) - Optional - The hardware device to use ('cuda', 'cpu', 'mps', or 'auto'). Defaults to 'auto' which attempts to find the best available device. - **threads** (int) - Optional - Number of threads to use for CPU inference. Defaults to 0 (auto-detection). ### Request Example ```python from zipvoice.luxvoice import LuxTTS # Load model on GPU (CUDA) lux_tts_cuda = LuxTTS('YatharthS/LuxTTS', device='cuda') # Load model on CPU with specified thread count lux_tts_cpu = LuxTTS('YatharthS/LuxTTS', device='cpu', threads=4) # Load model on Apple Silicon (MPS) lux_tts_mps = LuxTTS('YatharthS/LuxTTS', device='mps') # Auto-detection (falls back from CUDA to MPS, then CPU) lux_tts_auto = LuxTTS('YatharthS/LuxTTS', device='auto') ``` ### Response #### Success Response (200) An instance of the `LuxTTS` class is returned, ready for inference. #### Response Example ```python # No direct response object, but the lux_tts variable holds the loaded model instance. ``` ``` -------------------------------- ### LuxTTS Class Initialization and Device Loading Source: https://context7.com/ysharma3501/luxtts/llms.txt Demonstrates how to initialize the LuxTTS class for text-to-speech inference with voice cloning. It covers loading the model onto different devices like CUDA GPUs, Apple Silicon (MPS), and CPU using ONNX runtime optimization. The class automatically detects the best available device if not explicitly specified. ```python from zipvoice.luxvoice import LuxTTS # Load model on GPU (CUDA) lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # Load model on CPU with specified thread count lux_tts = LuxTTS('YatharthS/LuxTTS', device='cpu', threads=4) # Load model on Apple Silicon (MPS) lux_tts = LuxTTS('YatharthS/LuxTTS', device='mps') # Auto-detection: if CUDA unavailable, falls back to MPS, then CPU lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # Output: "CUDA not available, switching to MPS" or "CUDA not available, switching to CPU" ``` -------------------------------- ### Load LuxTTS Model Source: https://github.com/ysharma3501/luxtts/blob/master/README.md How to initialize the LuxTTS model on different hardware devices including CUDA, CPU, and MPS. ```python from zipvoice.luxvoice import LuxTTS # load model on GPU lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # load model on CPU # lux_tts = LuxTTS('YatharthS/LuxTTS', device='cpu', threads=2) # load model on MPS for macs # lux_tts = LuxTTS('YatharthS/LuxTTS', device='mps') ``` -------------------------------- ### LuxTTS Voice Cloning and Generation Source: https://context7.com/ysharma3501/luxtts/llms.txt Demonstrates the end-to-end voice cloning process using LuxTTS. This includes encoding a reference voice, generating speech from text with the cloned voice, and saving the audio output. It also shows how to generate multiple sentences with consistent voice quality. ```python import soundfile as sf from IPython.display import Audio, display from zipvoice.luxvoice import LuxTTS # Initialize the model lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # Step 1: Encode the reference voice # Note: First call may take ~10s due to librosa initialization prompt_audio = 'speaker_reference.wav' encoded_prompt = lux_tts.encode_prompt( prompt_audio, duration=5, # Use 5 seconds of reference rms=0.01 # Volume normalization ) # Step 2: Generate speech with the cloned voice text = """ Hey, what's up? I'm feeling really great if you ask me honestly! This is a demonstration of high-quality voice cloning. """ final_wav = lux_tts.generate_speech( text, encoded_prompt, num_steps=4, t_shift=0.9, speed=1.0, return_smooth=False ) # Step 3: Convert and save final_wav_np = final_wav.numpy().squeeze() sf.write('cloned_speech.wav', final_wav_np, 48000) # Optional: Display in Jupyter notebook display(Audio(final_wav_np, rate=48000)) # Generate multiple outputs with the same voice sentences = [ "First sentence with the cloned voice.", "Second sentence demonstrating consistency.", "Third sentence showing voice preservation." ] for i, sentence in enumerate(sentences): wav = lux_tts.generate_speech(sentence, encoded_prompt, num_steps=4) sf.write(f'output_{i}.wav', wav.numpy().squeeze(), 48000) ``` -------------------------------- ### Generate Speech with LuxTTS Source: https://context7.com/ysharma3501/luxtts/llms.txt This snippet demonstrates how to generate speech using the LuxTTS library. It requires pre-processed prompt features and a configured model, vocoder, and tokenizer to produce high-quality audio output. ```python wav = generate( prompt_tokens=prompt_tokens, prompt_features_lens=prompt_features_lens, prompt_features=prompt_features, prompt_rms=prompt_rms, text="Generated text here", model=model, vocoder=vocos, tokenizer=tokenizer, num_step=4, guidance_scale=3.0, t_shift=0.5, speed=1.0 ) ``` -------------------------------- ### Encoding Voice Prompts for Cloning Source: https://context7.com/ysharma3501/luxtts/llms.txt Explains how to use the `encode_prompt` method to capture voice characteristics from a reference audio file. This method supports various audio formats, transcribes the audio using Whisper, extracts mel-spectrogram features, and normalizes volume. Advanced options include controlling the duration of the reference audio used and the target RMS for volume normalization. ```python from zipvoice.luxvoice import LuxTTS lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # Basic prompt encoding (minimum 3 second audio recommended) prompt_audio = 'reference_voice.wav' # Supports WAV, MP3, and other formats encoded_prompt = lux_tts.encode_prompt(prompt_audio, rms=0.01) # Advanced prompt encoding with duration control # duration: Limits reference audio length (lower = faster inference) # rms: Volume normalization target (0.01 recommended for most cases) encoded_prompt = lux_tts.encode_prompt( prompt_audio, duration=5, # Use only first 5 seconds of reference rms=0.01 # Target RMS for volume normalization ) # For longer reference without artifacts, set duration higher encoded_prompt = lux_tts.encode_prompt( prompt_audio, duration=1000, # Use full reference audio (set high to include all) rms=0.01 ) # The encoded prompt contains: # - prompt_tokens: Tokenized transcription of the reference audio # - prompt_features_lens: Length of extracted features # - prompt_features: Mel-spectrogram features # - prompt_rms: Original RMS value for volume matching ``` -------------------------------- ### OnnxModel for Optimized CPU Inference Source: https://context7.com/ysharma3501/luxtts/llms.txt Implements ONNX-based models for efficient CPU inference, enabling faster speech generation on systems without GPU acceleration. It uses separate text encoder and flow-matching decoder sessions and provides utilities for loading models and generating audio on CPU. ```python from zipvoice.onnx_modeling import OnnxModel, generate_cpu from zipvoice.tokenizer.tokenizer import EmiliaTokenizer import torch # Initialize ONNX model with thread control model = OnnxModel( text_encoder_path='text_encoder.onnx', fm_decoder_path='fm_decoder.onnx', num_thread=4 # Control CPU thread usage ) # Access model properties feat_dim = model.feat_dim # Feature dimension from model metadata # Low-level text encoder inference tokens = torch.tensor([[1, 2, 3, 4, 5]], dtype=torch.int64) prompt_tokens = torch.tensor([[10, 11, 12]], dtype=torch.int64) prompt_features_len = torch.tensor(50, dtype=torch.int64) speed = torch.tensor(1.3, dtype=torch.float32) text_condition = model.run_text_encoder( tokens, prompt_tokens, prompt_features_len, speed ) # CPU generation (typically used via LuxTTS class) from zipvoice.modeling_utils import load_models_cpu model, feature_extractor, vocos, tokenizer, transcriber = load_models_cpu( model_path=None, # Downloads from HuggingFace num_thread=4 ) # Generate using CPU-optimized path final_wav = generate_cpu( prompt_tokens=[[1, 2, 3]], prompt_features_lens=torch.tensor([50]), prompt_features=torch.randn(1, 50, 100), prompt_rms=torch.tensor(0.01), text="Hello world", model=model, vocoder=vocos, tokenizer=tokenizer, num_step=4, guidance_scale=3.0, t_shift=0.9, speed=1.0 ) ``` -------------------------------- ### Model Loading Functions Source: https://context7.com/ysharma3501/luxtts/llms.txt Provides functions to load LuxTTS model components efficiently for GPU or CPU inference, along with access to model configuration. ```APIDOC ## Model Loading Functions Low-level functions for loading model components separately, useful for advanced customization or when integrating with custom pipelines. ### Loading Models for GPU Inference Loads all necessary components (model, feature extractor, vocoder, tokenizer, transcriber) onto the GPU. ```python from zipvoice.modeling_utils import load_models_gpu # Load all components for GPU inference model, feature_extractor, vocos, tokenizer, transcriber = load_models_gpu( model_path=None, # None downloads from HuggingFace Hub device='cuda' # or 'mps' for Apple Silicon ) ``` ### Loading Models for CPU Inference Loads components onto the CPU with optional ONNX optimization for faster inference. ```python from zipvoice.modeling_utils import load_models_cpu # Load for CPU with ONNX optimization model, feature_extractor, vocos, tokenizer, transcriber = load_models_cpu( model_path=None, num_thread=4 # Number of CPU threads ) ``` ### Loading from a Custom Path Loads model components from a specified local directory. ```python from zipvoice.modeling_utils import load_models_gpu # Custom model path (local directory) model, feature_extractor, vocos, tokenizer, transcriber = load_models_gpu( model_path='/path/to/local/model', device='cuda' ) ``` ### Accessing Model Configuration Retrieves and inspects the configuration object for LuxTTS. ```python from zipvoice.modeling_utils import LuxTTSConfig # Access configuration config = LuxTTSConfig() print(f"Tokenizer type: {config.tokenizer}") # 'emilia' print(f"Language: {config.lang}") # 'en-us' print(f"Checkpoint name: {config.checkpoint_name}") # 'model.pt' ``` ### Direct Generation and Audio Processing Functions for direct text-to-speech generation and processing reference audio. ```python from zipvoice.modeling_utils import generate, process_audio # Process reference audio prompt_tokens, prompt_features_lens, prompt_features, prompt_rms = process_audio( audio='reference.wav', transcriber=transcriber, # Assumes transcriber is loaded tokenizer=tokenizer, # Assumes tokenizer is loaded feature_extractor=feature_extractor, # Assumes feature_extractor is loaded device='cuda', target_rms=0.1, duration=5, feat_scale=0.1 ) ``` ``` -------------------------------- ### Extract Mel-Spectrogram Features with VocosFbank Source: https://context7.com/ysharma3501/luxtts/llms.txt Demonstrates initializing the VocosFbank feature extractor, loading audio, and performing mel-spectrogram extraction. It supports both PyTorch tensors and NumPy arrays, with automatic channel handling. ```python from zipvoice.utils.feature import VocosFbank import torch import torchaudio feature_extractor = VocosFbank(num_channels=1) waveform, sr = torchaudio.load('audio.wav') if sr != 24000: resampler = torchaudio.transforms.Resample(sr, 24000) waveform = resampler(waveform) features = feature_extractor.extract(waveform, sampling_rate=24000) feat_dim = feature_extractor.feature_dim(24000) frame_shift = feature_extractor.frame_shift import numpy as np audio_np = waveform.numpy() features_np = feature_extractor.extract(audio_np, sampling_rate=24000) stereo_waveform = torch.randn(2, 48000) features = feature_extractor.extract(stereo_waveform, sampling_rate=24000) ``` -------------------------------- ### Faster but lower quality generation Source: https://context7.com/ysharma3501/luxtts/llms.txt This snippet demonstrates a faster speech generation process by reducing the number of steps and adjusting the t_shift parameter. This approach prioritizes speed over the highest quality output. ```python import soundfile as sf # Assuming lux_tts and encoded_prompt are already defined # final_wav = lux_tts.generate_speech( # text="Quick generation test", # encode_dict=encoded_prompt, # num_steps=3, # Fewer steps = faster # t_shift=0.3 # Lower t_shift = fewer pronunciation errors # ) # Save with proper sample rate (always 48kHz) # sf.write('output.wav', final_wav.numpy().squeeze(), 48000) ``` -------------------------------- ### Generating Speech with Voice Cloning Source: https://context7.com/ysharma3501/luxtts/llms.txt Details the process of generating speech audio from text using an encoded voice prompt. The `generate_speech` method utilizes flow-matching with configurable sampling parameters for quality and speed. It returns a PyTorch tensor of the waveform at 48kHz. Advanced parameters like `guidance_scale`, `t_shift`, `speed`, and `return_smooth` are available to fine-tune the output and handle potential artifacts. ```python import soundfile as sf import torch from zipvoice.luxvoice import LuxTTS lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') encoded_prompt = lux_tts.encode_prompt('reference_voice.wav', rms=0.01) # Basic speech generation text = "Hello, this is a test of the voice cloning system." final_wav = lux_tts.generate_speech(text, encoded_prompt, num_steps=4) # Save the generated audio final_wav_np = final_wav.numpy().squeeze() sf.write('output.wav', final_wav_np, 48000) # Advanced generation with all sampling parameters final_wav = lux_tts.generate_speech( text="The quick brown fox jumps over the lazy dog.", encode_dict=encoded_prompt, num_steps=4, # Sampling steps: 3-4 is optimal for speed/quality guidance_scale=3.0, # Classifier-free guidance scale t_shift=0.5, # Temperature-like param: higher = better quality but worse WER speed=1.0, # Speech speed: lower = slower speech return_smooth=False # Set True if hearing metallic sounds ) # Handle metallic artifacts with smooth mode final_wav = lux_tts.generate_speech( text="Some text that sounds metallic", encode_dict=encoded_prompt, num_steps=4, t_shift=0.9, return_smooth=True # Smoother output, less crisp but no artifacts ) ``` -------------------------------- ### encode_prompt Source: https://context7.com/ysharma3501/luxtts/llms.txt Encodes a reference audio file to extract voice characteristics for voice cloning. This method is crucial for capturing the desired voice for speech generation. ```APIDOC ## encode_prompt ### Description Encodes a reference audio file to extract voice characteristics for cloning. It loads audio, transcribes it using Whisper, extracts mel-spectrogram features, and normalizes volume. The output can be reused for multiple speech generations with the same voice. ### Method `encode_prompt(audio_path: str, duration: int = 1000, rms: float = 0.01) -> dict` ### Parameters #### Path Parameters - **audio_path** (str) - Required - Path to the reference audio file (supports WAV, MP3, etc.). #### Query Parameters - **duration** (int) - Optional - Maximum duration (in seconds) of the reference audio to use. Set high to include the full audio. Defaults to 1000. - **rms** (float) - Optional - Target RMS value for volume normalization. Recommended value is 0.01. ### Request Example ```python from zipvoice.luxvoice import LuxTTS lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') # Basic prompt encoding prompt_audio = 'reference_voice.wav' encoded_prompt = lux_tts.encode_prompt(prompt_audio, rms=0.01) # Advanced prompt encoding with duration control encoded_prompt_limited = lux_tts.encode_prompt( prompt_audio, duration=5, # Use only the first 5 seconds rms=0.01 ) # Using full reference audio encoded_prompt_full = lux_tts.encode_prompt( prompt_audio, duration=1000, # Use entire audio file rms=0.01 ) ``` ### Response #### Success Response (200) A dictionary containing the encoded voice prompt. Keys include: - **prompt_tokens** (list) - Tokenized transcription of the reference audio. - **prompt_features_lens** (int) - Length of extracted features. - **prompt_features** (torch.Tensor) - Mel-spectrogram features. - **prompt_rms** (float) - Original RMS value for volume matching. #### Response Example ```json { "prompt_tokens": [101, 2054, 2003, 1037, ...], "prompt_features_lens": 128, "prompt_features": [[...], [...], ...], "prompt_rms": 0.015 } ``` ``` -------------------------------- ### Audio Utility Functions Source: https://context7.com/ysharma3501/luxtts/llms.txt A collection of helper functions for audio processing, including RMS normalization, silence removal, cross-fade concatenation, and format conversion. ```APIDOC ## Audio Utility Functions Helper functions for audio processing including RMS normalization, silence removal, cross-fade concatenation, and format conversion between PyTorch tensors and pydub AudioSegments. ### RMS Normalization Controls audio volume by normalizing the waveform to a target RMS value. ```python from zipvoice.utils.infer import rms_norm import torch waveform = torch.randn(1, 48000) normalized_wav, original_rms = rms_norm(waveform, target_rms=0.1) # Returns normalized waveform and original RMS for later matching ``` ### Silence Removal Removes silence from the beginning, end, or throughout the audio. ```python from zipvoice.utils.infer import remove_silence import torch # Remove all long silences with trailing silence cleaned_audio = remove_silence( audio=waveform, sampling_rate=24000, only_edge=False, # Remove all long silences trail_sil=100 # Add 100ms trailing silence ) # Edge silence removal only cleaned_audio = remove_silence( audio=waveform, sampling_rate=24000, only_edge=True # Only remove start/end silence ) ``` ### Cross-Fade Concatenation Seamlessly joins multiple audio chunks with a cross-fade effect. ```python from zipvoice.utils.infer import cross_fade_concat import torch chunks = [torch.randn(1, 24000), torch.randn(1, 24000), torch.randn(1, 24000)] combined = cross_fade_concat( chunks, fade_duration=0.1, # 100ms cross-fade sample_rate=24000 ) ``` ### Punctuation Handling Adds missing punctuation to text and chunks tokens while respecting punctuation and token limits. ```python from zipvoice.utils.infer import add_punctuation, chunk_tokens_punctuation # Add punctuation if missing text = add_punctuation("Hello world") # Returns "Hello world." # Chunk tokens for long text processing tokens = ['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '.'] chunks = chunk_tokens_punctuation(tokens, max_tokens=100) # Splits at punctuation, respects max token limit ``` ### Loading Prompt Audio Loads and resamples an audio file to be used as a prompt. ```python from zipvoice.utils.infer import load_prompt_wav prompt_wav = load_prompt_wav('audio.wav', sampling_rate=24000) # Automatically resamples if needed ``` ``` -------------------------------- ### generate_speech Source: https://context7.com/ysharma3501/luxtts/llms.txt Generates speech audio from input text using an encoded voice prompt. Allows customization of sampling parameters for quality and speed. ```APIDOC ## generate_speech ### Description Generates speech audio from text using an encoded voice prompt. It employs flow-matching with configurable sampling parameters to control quality, speed, and pronunciation. Returns a PyTorch tensor containing the 48kHz waveform. ### Method `generate_speech(text: str, encode_dict: dict, num_steps: int = 4, guidance_scale: float = 3.0, t_shift: float = 0.5, speed: float = 1.0, return_smooth: bool = False) -> torch.Tensor` ### Parameters #### Path Parameters None #### Query Parameters - **text** (str) - Required - The input text to convert to speech. - **encode_dict** (dict) - Required - The dictionary returned by `encode_prompt` containing the voice characteristics. - **num_steps** (int) - Optional - Number of sampling steps. 3-4 is optimal for speed/quality. Defaults to 4. - **guidance_scale** (float) - Optional - Classifier-free guidance scale. Defaults to 3.0. - **t_shift** (float) - Optional - Temperature-like parameter. Higher values improve quality but may worsen Word Error Rate (WER). Defaults to 0.5. - **speed** (float) - Optional - Speech speed multiplier. Lower values result in slower speech. Defaults to 1.0. - **return_smooth** (bool) - Optional - If True, returns a smoother output to mitigate metallic artifacts, potentially at the cost of crispness. Defaults to False. ### Request Example ```python import soundfile as sf import torch from zipvoice.luxvoice import LuxTTS lux_tts = LuxTTS('YatharthS/LuxTTS', device='cuda') encoded_prompt = lux_tts.encode_prompt('reference_voice.wav', rms=0.01) # Basic speech generation text_to_speak = "Hello, this is a test of the voice cloning system." final_wav = lux_tts.generate_speech(text_to_speak, encoded_prompt, num_steps=4) # Save the generated audio final_wav_np = final_wav.numpy().squeeze() sf.write('output.wav', final_wav_np, 48000) # Advanced generation with all sampling parameters final_wav_advanced = lux_tts.generate_speech( text="The quick brown fox jumps over the lazy dog.", encode_dict=encoded_prompt, num_steps=4, guidance_scale=3.0, t_shift=0.5, speed=1.0, return_smooth=False ) # Handling metallic artifacts with smooth mode final_wav_smooth = lux_tts.generate_speech( text="Some text that sounds metallic", encode_dict=encoded_prompt, num_steps=4, t_shift=0.9, return_smooth=True ) ``` ### Response #### Success Response (200) A PyTorch tensor containing the generated speech waveform at 48kHz. #### Response Example ```python # A PyTorch tensor representing the audio waveform, e.g.: # tensor([[-0.0001, -0.0002, -0.0003, ..., 0.0002, 0.0001, 0.0000]]) ``` ``` -------------------------------- ### EmiliaTokenizer for Text-to-Phoneme Conversion Source: https://context7.com/ysharma3501/luxtts/llms.txt Utilizes EmiliaTokenizer for converting text into phoneme tokens, supporting English and Chinese with automatic language detection and text normalization. It handles mixed-language inputs and special pinyin notations. ```python from zipvoice.tokenizer.tokenizer import EmiliaTokenizer # Initialize with token vocabulary file tokenizer = EmiliaTokenizer(token_file='tokens.txt') # Convert text to token IDs for model input texts = ["Hello, how are you today?"] token_ids = tokenizer.texts_to_token_ids(texts) # Returns: [[token_id1, token_id2, ...]] # Convert text to phoneme tokens (intermediate representation) tokens = tokenizer.texts_to_tokens(texts) # Returns: [['h', 'ə', 'l', 'oʊ', ...]] # Mixed English and Chinese text mixed_text = ["我们是5年小米人,是吗? Yes I think so!"] tokens = tokenizer.texts_to_tokens(mixed_text) # Automatically detects and processes both languages # Using pinyin notation for specific pronunciation text_with_pinyin = ["This is a test word"] tokens = tokenizer.texts_to_tokens(text_with_pinyin) # Pinyin in <> brackets is processed as Chinese phonemes # Access tokenizer properties print(f"Vocabulary size: {tokenizer.vocab_size}") print(f"Padding token ID: {tokenizer.pad_id}") # Preprocessing text (punctuation normalization) normalized = tokenizer.preprocess_text("你好,世界!") # Converts Chinese punctuation to ASCII equivalents ``` -------------------------------- ### VocosFbank Feature Extractor Source: https://context7.com/ysharma3501/luxtts/llms.txt Utilize the VocosFbank class to compute mel-spectrogram features from audio waveforms. It is configured for 24kHz input with 100 mel bins, suitable for the LuxTTS pipeline. ```APIDOC ## VocosFbank Feature extractor for computing mel-spectrogram features from audio waveforms. Configured for 24kHz input with 100 mel bins, optimized for the LuxTTS pipeline. ### Usage Example ```python from zipvoice.utils.feature import VocosFbank import torch import torchaudio # Initialize feature extractor feature_extractor = VocosFbank(num_channels=1) # Load and prepare audio waveform, sr = torchaudio.load('audio.wav') if sr != 24000: resampler = torchaudio.transforms.Resample(sr, 24000) waveform = resampler(waveform) # Extract mel-spectrogram features features = feature_extractor.extract(waveform, sampling_rate=24000) # Returns: torch.Tensor of shape (time, n_mels) = (time, 100) # Get feature dimension feat_dim = feature_extractor.feature_dim(24000) # Returns 100 # Get frame shift in seconds frame_shift = feature_extractor.frame_shift # hop_length / sample_rate # Process numpy arrays import numpy as np audio_np = waveform.numpy() features_np = feature_extractor.extract(audio_np, sampling_rate=24000) # Returns numpy array if input is numpy # Handle stereo audio (auto-converts to mono for single channel mode) stereo_waveform = torch.randn(2, 48000) # 2 channels features = feature_extractor.extract(stereo_waveform, sampling_rate=24000) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.