### Install ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blob/4d9765a6d79744fe64f7d68ff993795f74c2e8fa/README.md Instructions for cloning the repository and installing dependencies. ```APIDOC ## Install ViZipvoice ``` git clone https://github.com/iamdinhthuan/ViZipvoice.git cd ViZipvoice pip install -r requirements.txt export PYTHONPATH="$PWD:$PYTHONPATH" ``` ``` -------------------------------- ### Install requirements Source: https://huggingface.co/contextboxai/ViZipvoice/commits/4f7cce6974b15a37fe31279679c2b04cecd62ff0 This snippet shows how to install the project dependencies using pip. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install ViZipVoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/03e26b4283e42a8927f0bd34613636c41c00a6a1/README.md Clone the repository, install dependencies, and set the Python path to use ViZipVoice. ```bash git clone https://github.com/iamdinhthuan/ViZipvoice.git cd ViZipvoice pip install -r requirements.txt export PYTHONPATH="$PWD:$PYTHONPATH" ``` -------------------------------- ### Example Usage Placeholder Source: https://huggingface.co/contextboxai/ViZipvoice/blame/78e0caa6720d4939eed21c1f2942c4c2ffa3e9dc/audio/Linh-Anh.txt This snippet appears to be a placeholder or an incomplete example related to the ViZipvoice model. ```text 1 ``` -------------------------------- ### Model Metadata File Example Source: https://huggingface.co/contextboxai/ViZipvoice/commits/70503572b5202ef90278821bddd54f86eb3325fb?p=1 This is an example of a model.json file, likely containing metadata or configuration details for the ViZipvoice model. ```json { "model_name": "ViZipvoice", "version": "1.0", "description": "A Vietnamese text-to-speech model.", "author": "ContextBoxAI" } ``` -------------------------------- ### Example Usage Placeholder 2 Source: https://huggingface.co/contextboxai/ViZipvoice/blame/78e0caa6720d4939eed21c1f2942c4c2ffa3e9dc/audio/Linh-Anh.txt This snippet appears to be a placeholder or an incomplete example related to the ViZipvoice model. ```text 2 ``` -------------------------------- ### README.md Content Source: https://huggingface.co/contextboxai/ViZipvoice/commits/8bb32468c851f1262d2578d564ca11c789a051f8 This snippet contains the content of the README.md file, which typically provides an overview, installation instructions, and usage examples for the project. ```markdown # ViZipvoice ViZipvoice is a Vietnamese text-to-speech model based on the Zip-Voice architecture. ## Features * High-quality Vietnamese speech synthesis * Zero-shot voice cloning capabilities * PyTorch implementation ## Installation ```bash pip install torch transformers scipy numpy ``` ## Usage ```python from vizipvoice import ViZipvoice # Load the model model = ViZipvoice(model_path="./checkpoint-700000", config_path="./config.json", tokenizer_path="./tokens.txt") # Synthesize speech text = "Xin chào, đây là giọng nói được tạo ra bởi ViZipvoice." model.synthesize(text, speaker_id=0, output_path="output.wav") print("Speech synthesis complete. Check the output.wav file.") ``` ## Model The model was trained on a custom dataset of Vietnamese speech. ## License This project is licensed under the Apache 2.0 License. ``` -------------------------------- ### Python Wrapper Source: https://huggingface.co/contextboxai/ViZipvoice/blob/4d9765a6d79744fe64f7d68ff993795f74c2e8fa/README.md Example of using the ViZipVoiceTTS Python class for synthesizing speech. ```APIDOC ## Python ``` from zipvoice.vizipvoice import ViZipVoiceTTS tts = ViZipVoiceTTS() metrics = tts.synthesize( prompt_wav="prompt.wav", prompt_text="Xin chào, đây là giọng mẫu của tôi.", text="Đây là câu tiếng Việt được sinh bởi ViZipVoice.", output_path="output.wav", ) print(metrics) ``` ``` -------------------------------- ### Tokenization Example Source: https://huggingface.co/contextboxai/ViZipvoice/blame/6093a4b65e40ef5b36648b7b12b37210aa67bc6e/tokens.txt This snippet demonstrates the tokenization process for the ViZipvoice model. It maps characters to their corresponding integer IDs. ```python _\t1\nn\th\ti\tc\tg\ta\tm\tu\to\tr\tà\đ\tl\ư\ty\tv\te\ts\tá\tb\tp\t.\t,\tk\td\tộ\tô\tế\tạ\tả\tó\tă\tê\tố\tT\ttờ\tì\tệ\tơ\tâ\tớ\tấ\tủ\tí\tợ\tể\tề\tN\tậ\tầ\tC\tq\tị\tx\tự\tọ\tã\tH\tứ\tở\tú\tữ\tắ\tM\tồ\tu\tB\tL\tổ\tù\từ\tò\tĐ\tặ\tK\tf\tP\tw\tV\tử\tS\tỉ\tA\tũ\tD\té\tỏ\tằ\tG\tý\tẩ\tQ\tĩ\tẽ\tI\tễ\tã\tỗ\t)\t(\t:\tR\t-\tỳ\tẻ\tẹ\tỹ\tE\t?\tz\tF\tõ\t'\tỷ\tX\tè\tO\tỡ\tẳ\tJ\tW\tY\tj\tU\t!\tẤ\t;\tÂ\tÁ\tÔ\tẵ\tZ\t/\tÝ\ty\tỦ\tÚ\t&\t"\tỞ\tẢ\tƯ\t+\t*\tÉ\t$ \tỨ\tÍ\tĂ\tÀ\t#\tỪ\t~\tẨ\tỐ\tÊ\t’\t=\tỒ\tỶ\tƠ\tỜ\tỔ\tÓ\tẾ\t[\t{\t}\t%\t0\t2\t@\t^\t\\\tẠ\t]\tẦ\tỚ\tẬ\tỘ\tỊ\tỤ\tỸ\tỆ\tÌ\tÙ\t5\tỀ\tÒ\t1\tĨ\tỎ\t–\tẮ\t8\tỌ\t3\tỂ\tỢ\tỰ\tÃ\tẲ\tỄ\tỬ\tẸ\tỈ\tẶ\ṭ\tÈ\t́\tñ\t4\t9\tỮ\tŨ\tỲ\t̀\tÕ\tö\t6\tẼ\tẴ\t̉\tẺ\t̃\t—\tẪ\t…\tẰ\t”\tỗ\t>\tỠ\t<\tû\t7\tỴ\tç\tð\të\tØ ``` -------------------------------- ### File Content Example Source: https://huggingface.co/contextboxai/ViZipvoice/blame/03e26b4283e42a8927f0bd34613636c41c00a6a1/checkpoint-700000.pt Displays the content of a file, which in this case is a Git LFS pointer. ```text 361c408     ``` -------------------------------- ### Example Text Input Source: https://huggingface.co/contextboxai/ViZipvoice/blame/1cdd6d455d27848ee6293831e26f2384ca9642ee/audio/MC.txt This is an example of Vietnamese text that can be used as input for the ViZipvoice model. ```text Đo lường phản ứng của nhà sản xuất với biện pháp điều chỉnh giá là rất cần thiết. ``` -------------------------------- ### Tokens File Example Source: https://huggingface.co/contextboxai/ViZipvoice/commits/70503572b5202ef90278821bddd54f86eb3325fb?p=1 This file, tokens.txt, likely contains a list of tokens or vocabulary used by the ViZipvoice model for processing text. ```text a ă â b c ch d đ e ê g gh h i k l l m n nh o ô ơ p h r s t th u ư v x ``` -------------------------------- ### ViZipvoice Generation Example Source: https://huggingface.co/contextboxai/ViZipvoice/blame/fa3a83e37e9572033249f5e3276cc50ec8a02aad/demo/metadata.json This snippet demonstrates how to generate speech from text using the ViZipvoice model. It includes parameters for output file, prompt audio, text content, and various generation settings like seed, steps, guidance scale, and audio processing. ```json { "output": "demo_01_Đinh-Quyết.wav", "prompt_audio": "audio/Đinh-Quyết.mp3", "prompt_text": "Trong trang, việc ứng dụng công nghệ và chuyển đổi số đang là yếu tố chi phối các mô hình này.", "text": "Chiến tranh luôn là một chủ đề nặng nề, nhưng cũng rất cần được nhắc đến để con người hiểu rõ hơn giá trị của hòa bình. Khi một cuộc chiến xảy ra, những gì bị phá hủy không chỉ là nhà cửa, đường sá, trường học hay bệnh viện. Điều đau lòng nhất chính là sinh mạng con người, là những gia đình bị chia cắt, là những đứa trẻ phải lớn lên trong sợ hãi, và là những vùng đất từng yên bình bỗng trở nên hoang tàn.", "seed": 667, "num_step": 16, "guidance_scale": 1.0, "speed": 1.0, "t_shift": 0.5, "split_sentences": true, "crossfade_ms": 80, "silence_ms": 180, "fade_in_ms": 20, "fade_out_ms": 80, "metrics": { "t": 1.377809762954712, "t_no_vocoder": 1.279067, "t_vocoder": 0.033847, "wav_seconds": 18.099, "rtf": 0.07612629222358759, "rtf_no_vocoder": 0.07067058953533344, "rtf_vocoder": 0.001870103320625449, "segments": 3, "segment_settings": [ { "index": 1, "word_count": 27, "speed": 1.0, "num_step": 16, ``` -------------------------------- ### Voice Cloning with ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/ce80eb3bc9aa1264e40d53be402b05b25a353d25/tokens.txt This example shows how to perform voice cloning using the ViZipvoice model. It requires providing a reference audio file for the target voice. ```python from transformers import pipeline pipe = pipeline("text-to-speech", model="contextboxai/ViZipvoice") # Load a reference audio file (e.g., 'reference.wav') # The pipeline will extract the voice characteristics from this file. output = pipe("Đây là giọng nói được sao chép.", forward_params={"audio_file": "reference.wav"}) # Save the generated audio # import soundfile as sf # sf.write("cloned_voice_output.wav", output["audio"], output["sampling_rate"]) ``` -------------------------------- ### Example Usage of ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/42e16314a96fed670ef6f96fa0c15235e1d95caf/audio/MC.txt This snippet demonstrates how to use the ViZipvoice model for text-to-speech synthesis. It requires the model to be loaded and then used to convert text into speech. ```python from transformers import pipeline pipe = pipeline("text-to-speech", model="ContextBoxAI/ViZipvoice") output = pipe("Đo lường phản ứng của nhà sản xuất với biện pháp điều chỉnh giá là rất cần thiết.") # The output is a dictionary containing the audio array and sampling rate. # You can save it to a file like this: # import soundfile as sf # sf.write("output.wav", output["audio"], output["sampling_rate"]) ``` -------------------------------- ### Basic Text-to-Speech Synthesis Source: https://huggingface.co/contextboxai/ViZipvoice/blame/ce80eb3bc9aa1264e40d53be402b05b25a353d25/tokens.txt This snippet demonstrates how to use the ViZipvoice model for basic text-to-speech synthesis. Ensure you have the necessary libraries installed. ```python from transformers import pipeline pipe = pipeline("text-to-speech", model="contextboxai/ViZipvoice") output = pipe("Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói.") # The output is a dictionary containing the audio data and sampling rate. # You can save it to a file like this: # import soundfile as sf # sf.write("output.wav", output["audio"], output["sampling_rate"]) ``` -------------------------------- ### Example Text for ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/1cdd6d455d27848ee6293831e26f2384ca9642ee/demo/demo_text.txt This is an example of Vietnamese text that can be used with the ViZipvoice model for text-to-speech generation. ```text Chiến tranh luôn là một chủ đề nặng nề, nhưng cũng rất cần được nhắc đến để con người hiểu rõ hơn giá trị của hòa bình. Khi một cuộc chiến xảy ra, những gì bị phá hủy không chỉ là nhà cửa, đường sá, trường học hay bệnh viện. Điều đau lòng nhất chính là sinh mạng con người, là những gia đình bị chia cắt, là những đứa trẻ phải lớn lên trong sợ hãi, và là những vùng đất từng yên bình bỗng trở nên hoang tàn. ``` -------------------------------- ### Tokenization Example Source: https://huggingface.co/contextboxai/ViZipvoice/blame/eb78083f3e77ecf385086c795207776f7219b89a/tokens.txt This snippet demonstrates how to tokenize Vietnamese text using the model's tokenizer. It maps characters to their corresponding integer IDs. ```python from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("contextboxai/ViZipvoice") text = "Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói." encoded_input = tokenizer(text, return_tensors='pt') print(encoded_input) ``` -------------------------------- ### Load and Use ViZipvoice Model Source: https://huggingface.co/contextboxai/ViZipvoice/blame/f23fd759259b3fe6b8443c4625f5e032afa8076d/tokens.txt This snippet shows how to load the ViZipvoice model and use it to synthesize speech from Vietnamese text. Ensure you have the necessary libraries installed. ```python from transformers import pipeline pipeline("text-to-speech", model="contextboxai/ViZipvoice") ``` -------------------------------- ### Normalize Vietnamese Text Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Normalizes Vietnamese text using the 'soe-vinorm' library. Requires 'soe-vinorm' to be installed (`pip install soe-vinorm`). ```python def normalize_vietnamese_text(text: str, enabled: bool = True) -> str: if not enabled: return text.strip() try: from soe_vinorm import normalize_text except ImportError as exc: raise RuntimeError( "Vietnamese normalization requires soe-vinorm. " "Install it with `pip install soe-vinorm`." ) from exc return cleanup_vietnamese_spacing(normalize_text(text)) ``` -------------------------------- ### Download Model and Run Gradio App Source: https://huggingface.co/contextboxai/ViZipvoice/blob/0d9339b43961a4000b9f27017975b97c154e1d90/README.md Download the model files locally using the Hugging Face CLI and then run the Gradio application for interactive use. ```bash huggingface-cli download contextboxai/ViZipvoice \ --local-dir models/ViZipvoice \ --local-dir-use-symlinks False python3 egs/zipvoice/gradio_app.py --exp-dir models/ViZipvoice ``` -------------------------------- ### Download Model with Hugging Face CLI Source: https://huggingface.co/contextboxai/ViZipvoice/blob/03e26b4283e42a8927f0bd34613636c41c00a6a1/README.md Download the ViZipvoice model repository locally using the Hugging Face CLI. Use --local-dir-use-symlinks False to avoid symlinks. ```bash huggingface-cli download contextboxai/ViZipvoice \ --local-dir models/ViZipvoice \ --local-dir-use-symlinks False ``` -------------------------------- ### Download Model and Run Gradio App Source: https://huggingface.co/contextboxai/ViZipvoice/blob/03e26b4283e42a8927f0bd34613636c41c00a6a1/README.md?code=true Download the model files locally using huggingface-cli and then run the Gradio application, specifying the experiment directory. ```bash huggingface-cli download contextboxai/ViZipvoice \ --local-dir models/ViZipvoice \ --local-dir-use-symlinks False python3 egs/zipvoice/gradio_app.py --exp-dir models/ViZipvoice ``` -------------------------------- ### Launch Gradio App Source: https://huggingface.co/contextboxai/ViZipvoice/blame/1493284d75c13ee38fce0d8dfb72badfc512d8e3/README.md Run the Gradio interface for ViZipVoice, specifying the experiment directory where the model is located. This provides a web-based UI for inference. ```bash python3 egs/zipvoice/gradio_app.py --exp-dir models/ViZipvoice ``` -------------------------------- ### Initialize ViZipVoice Model Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Initializes the ViZipVoice model, tokenizer, and vocoder. Ensure the model configuration, checkpoint, and token files are accessible. ```python self.tokenizer = SimpleTokenizer(token_file=str(self.token_file)) self.model = ZipVoice( **self.model_config["model"], vocab_size=self.tokenizer.vocab_size, pad_id=self.tokenizer.pad_id, ) self._load_checkpoint() self.model.to(self.device) self.model.eval() self.feature_extractor = VocosFbank() self.vocoder = get_vocoder(str(vocoder_path) if vocoder_path else None) self.vocoder.to(self.device) self.vocoder.eval() self.sampling_rate = int(self.model_config["feature"]["sampling_rate"]) logging.info( "Loaded ViZipVoice from %s on %s | fp16 autocast: %s", self.checkpoint_path, self.device, self.use_fp16, ) ``` -------------------------------- ### Download ViZipvoice Model Files Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Downloads the specified checkpoint, model configuration, and token files for ViZipvoice from Hugging Face Hub. It resolves the correct checkpoint name if 'latest' is provided. ```python def _download_model_files( repo_id: str, revision: Optional[str], checkpoint_name: str, ) -> tuple[Path, Path, Path]: checkpoint_name = _resolve_hf_checkpoint_name( repo_id=repo_id, revision=revision, checkpoint_name=checkpoint_name, ) checkpoint_path = Path( hf_hub_download( repo_id=repo_id, filename=checkpoint_name, revision=revision, ) ) model_config_path = _download_config_file( repo_id=repo_id, revision=revision, ) token_file = Path( hf_hub_download( repo_id=repo_id, filename="tokens.txt", revision=revision, ) ) return checkpoint_path, model_config_path, token_file ``` -------------------------------- ### Get Sentence Inference Parameters Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Determines inference parameters (number of steps, speed, word count) based on the number of words in a sentence. Adjusts parameters for sentences with 1, 2-4, or more words. ```python def get_sentence_inference_params( sentence: str, base_num_step: int, base_speed: float, ) -> tuple[int, float, int]: word_count = count_sentence_words(sentence) if word_count == 1: return max(base_num_step, 24), 0.6, word_count if 2 <= word_count <= 4: return base_num_step, 0.8, word_count return base_num_step, base_speed, word_count ``` -------------------------------- ### Download ViZipvoice Model and Run Gradio App Source: https://huggingface.co/contextboxai/ViZipvoice/blame/0d9339b43961a4000b9f27017975b97c154e1d90/README.md Download the ViZipvoice model locally for use with the Gradio application. The command specifies the model repository and local directory for storage. ```bash huggingface-cli download contextboxai/ViZipvoice \ --local-dir models/ViZipvoice \ --local-dir-use-symlinks False ``` ```bash python3 egs/zipvoice/gradio_app.py --exp-dir models/ViZipvoice ``` -------------------------------- ### ViZipvoice Model Configuration Source: https://huggingface.co/contextboxai/ViZipvoice/blame/1cdd6d455d27848ee6293831e26f2384ca9642ee/config.json This JSON object defines the configuration parameters for the ViZipvoice text-to-speech model. It includes details about the model architecture, tokenizer, text normalizer, reference audio setup, and specific layer configurations for the text encoder and feature decoder. ```json { "architectures": [ "ZipVoice" ], "model_type": "zipvoice", "library_name": "pytorch", "pipeline_tag": "text-to-speech", "checkpoint": "checkpoint-1300000.pt", "dataset_hours": 7000, "tokenizer": { "type": "SimpleTokenizer", "level": "character", "vocab_size": 244, "token_file": "tokens.txt" }, "text_normalizer": { "package": "soe-vinorm", "enabled_by_default": true, "postprocess": "remove extra spaces around punctuation" }, "reference_audio": { "directory": "audio", "count": 30, "text_format": "sidecar_txt_same_basename" }, "demo": { "directory": "demo", "sample_count": 3 }, "model": { "fm_decoder_downsampling_factor": [ 1, 2, 4, 2, 1 ], "fm_decoder_num_layers": [ 2, 2, 4, 4, 4 ], "fm_decoder_cnn_module_kernel": [ 31, 15, 7, 15, 31 ], "fm_decoder_feedforward_dim": 1536, "fm_decoder_num_heads": 4, "fm_decoder_dim": 512, "text_encoder_num_layers": 4, "text_encoder_feedforward_dim": 512, "text_encoder_cnn_module_kernel": 9, "text_encoder_num_heads": 4, "text_encoder_dim": 192, "query_head_dim": 32, "value_head_dim": 12, "pos_head_dim": 4, "pos_dim": 48, "time_embed_dim": 192, "text_embed_dim": 192, "feat_dim": 100 }, "feature": { "sampling_rate": 24000, "type": "vocos" } } ``` -------------------------------- ### CLI Inference with ViZipVoice Source: https://huggingface.co/contextboxai/ViZipvoice/blob/0d9339b43961a4000b9f27017975b97c154e1d90/README.md?code=true Use the command-line interface to synthesize speech from a prompt audio and text. The model repository is downloaded by default. Specify a local model directory using `--model-dir` if files are already downloaded. ```bash python3 -m zipvoice.bin.infer_vizipvoice \ --prompt-wav prompt.wav \ --prompt-text "Xin chào, đây là giọng mẫu của tôi." \ --text "ViZipVoice có thể tổng hợp giọng nói tiếng Việt từ một đoạn mẫu ngắn." \ --res-wav-path output.wav ``` -------------------------------- ### Download Model Configuration File Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Attempts to download either 'config.json' or 'model.json' from the specified Hugging Face repository. Raises FileNotFoundError if neither is found. ```python def _download_config_file(repo_id: str, revision: Optional[str]) -> Path: last_error = None for filename in ("config.json", "model.json"): try: return Path( hf_hub_download( repo_id=repo_id, filename=filename, revision=revision, ) ) except Exception as exc: last_error = exc raise FileNotFoundError("No config.json or model.json file found.") from last_error ``` -------------------------------- ### Initialize ViZipVoiceTTS Model Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Initializes the ViZipVoiceTTS model, handling model file downloads or local path resolution, and setting up the device and precision (FP16 for CUDA). ```python class ViZipVoiceTTS: """Small wrapper for Vietnamese ZipVoice inference. The wrapper downloads model files from Hugging Face by default, builds the ZipVoice model with the Vietnamese character tokenizer, and exposes a single synthesize method. """ def __init__( self, repo_id: str = DEFAULT_REPO_ID, revision: Optional[str] = None, model_dir: Optional[Union[str, Path]] = None, checkpoint_name: str = DEFAULT_CHECKPOINT_NAME, vocoder_path: Optional[Union[str, Path]] = None, device: Optional[Union[str, torch.device]] = None, use_fp16: bool = True, num_threads: int = 1, ) -> None: try: torch.set_num_threads(num_threads) torch.set_num_interop_threads(num_threads) except RuntimeError: logging.debug("PyTorch thread settings were already initialized.") self.repo_id = repo_id self.revision = revision self.device = _resolve_device(device) self.use_fp16 = bool(use_fp16 and self.device.type == "cuda") if model_dir is None: checkpoint_path, model_config_path, token_file = _download_model_files( repo_id=repo_id, revision=revision, checkpoint_name=checkpoint_name, ) else: model_dir = Path(model_dir) checkpoint_path = _resolve_local_checkpoint_path( model_dir=model_dir, checkpoint_name=checkpoint_name, ) model_config_path = _resolve_local_config_path(model_dir) token_file = model_dir / "tokens.txt" self.checkpoint_path = Path(checkpoint_path) self.model_config_path = Path(model_config_path) self.token_file = Path(token_file) self._validate_model_files() with self.model_config_path.open("r", encoding="utf-8") as f: self.model_config = json.load(f) ``` -------------------------------- ### Initial commit Source: https://huggingface.co/contextboxai/ViZipvoice/commits/64160661736ec22279e3ecdc1dd6b89380bb7ebf This snippet represents the initial commit for the ViZipvoice project. ```git Initial commit ``` -------------------------------- ### Generate Speech from Text Source: https://huggingface.co/contextboxai/ViZipvoice/blame/b63b98af788985159c89bc8f6e31346c558431fa/demo/metadata.json This snippet demonstrates how to generate speech from a given text prompt using the ViZipvoice model. It includes parameters for output file name, prompt audio, prompt text, the actual text to synthesize, and various generation settings like seed, number of steps, guidance scale, speed, and audio processing parameters. ```python [ { "output": "demo_01_Đinh-Quyết.wav", "prompt_audio": "audio/Đinh-Quyết.mp3", "prompt_text": "Trong trang, việc ứng dụng công nghệ và chuyển đổi số đang là yếu tố chi phối các mô hình này.", "text": "Chiến tranh luôn là một chủ đề nặng nề, nhưng cũng rất cần được nhắc đến để con người hiểu rõ hơn giá trị của hòa bình. Khi một cuộc chiến xảy ra, những gì bị phá hủy không chỉ là nhà cửa, đường sá, trường học hay bệnh viện. Điều đau lòng nhất chính là sinh mạng con người, là những gia đình bị chia cắt, là những đứa trẻ phải lớn lên trong sợ hãi, và là những vùng đất từng yên bình bỗng trở nên hoang tàn.", "seed": 667, "num_step": 16, "guidance_scale": 1.0, "speed": 1.0, "t_shift": 0.5, "split_sentences": true, "crossfade_ms": 80, "silence_ms": 180, "fade_in_ms": 20, "fade_out_ms": 80, "metrics": { "t": 1.377809762954712, "t_no_vocoder": 1.279067, "t_vocoder": 0.033847, "wav_seconds": 18.099, "rtf": 0.07612629222358759, "rtf_no_vocoder": 0.07067058953533344, "rtf_vocoder": 0.001870103320625449, "segments": 3, "segment_settings": [ { "index": 1, "word_count": 27, "speed": 1.0, "num_step": 16, ``` -------------------------------- ### Basic Text-to-Speech with pipeline Source: https://huggingface.co/contextboxai/ViZipvoice/commits/4f7cce6974b15a37fe31279679c2b04cecd62ff0 This snippet demonstrates basic text-to-speech synthesis using the Hugging Face pipeline. ```python from transformers import pipeline # Load the ViZipvoice model synthesizer = pipeline("text-to-speech", model="contextboxai/ViZipvoice") # Synthesize speech text = "Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói." speech = synthesizer(text) # The output 'speech' is a dictionary containing audio data and sampling rate # You can save it to a file using libraries like soundfile import soundfile as sf sf.write("output.wav", speech["audio"], speech["sampling_rate"]) ``` -------------------------------- ### ViZipvoice Python Script Source: https://huggingface.co/contextboxai/ViZipvoice/commits/5a2eaf35fb2065c69c3f921312b3293a5f299b52?p=1 This script demonstrates the core functionality of the ViZipvoice model. It requires the 'torch' and 'transformers' libraries. Ensure the model and configuration files are accessible. ```python import torch from transformers import AutoModelForTextToSpeech, AutoTokenizer model_name = "contextboxai/ViZipvoice" model = AutoModelForTextToSpeech.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) def synthesize_speech(text, speaker_id=0, output_path="output.wav"): inputs = tokenizer(text, return_tensors="pt") with torch.no_grad(): speech, _ = model.synthesize(**inputs, speaker_id=speaker_id) # Save the synthesized speech to a WAV file # Note: This part requires an audio writing library like `scipy.io.wavfile` or `soundfile` # Example using scipy (install with: pip install scipy): # from scipy.io.wavfile import write as write_wav # write_wav(output_path, model.config.sampling_rate, speech.squeeze().cpu().numpy()) print(f"Speech synthesized and saved to {output_path}") # Example usage: synthesize_speech("Xin chào, đây là giọng nói được tạo ra bởi ViZipvoice.") ``` -------------------------------- ### Upload README.md Source: https://huggingface.co/contextboxai/ViZipvoice/commits/4f7cce6974b15a37fe31279679c2b04cecd62ff0 This snippet contains the README content for the ViZipvoice project. ```markdown # ViZipvoice ViZipvoice is a Vietnamese text-to-speech model developed by ContextBoxAI. ## Features * **High-quality Vietnamese TTS**: Generates natural-sounding Vietnamese speech. * **Zero-shot TTS**: Can synthesize speech in voices it hasn't been explicitly trained on, given a reference audio sample. * **Voice Cloning**: Capable of cloning voices from short audio samples. ## Installation ```bash pip install -r requirements.txt ``` ## Usage ### Basic Text-to-Speech ```python from transformers import pipeline # Load the ViZipvoice model synthesizer = pipeline("text-to-speech", model="contextboxai/ViZipvoice") # Synthesize speech text = "Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói." speech = synthesizer(text) # The output 'speech' is a dictionary containing audio data and sampling rate # You can save it to a file using libraries like soundfile import soundfile as sf sf.write("output.wav", speech["audio"], speech["sampling_rate"]) ``` ### Zero-shot TTS / Voice Cloning To use ViZipvoice for zero-shot TTS or voice cloning, you need to provide a reference audio file. ```python from transformers import pipeline # Load the ViZipvoice model synthesizer = pipeline("text-to-speech", model="contextboxai/ViZipvoice") # Synthesize speech using a reference audio file for voice cloning text = "Đây là giọng nói được tạo ra từ một mẫu âm thanh tham chiếu." reference_audio_path = "path/to/your/reference_audio.wav" speech = synthesizer(text, audio_path=reference_audio_path) # Save the synthesized speech sf.write("cloned_voice_output.wav", speech["audio"], speech["sampling_rate"]) ``` **Note**: The `audio_path` parameter is used for zero-shot TTS and voice cloning. Ensure the reference audio is of good quality and in a compatible format (e.g., WAV). ## Model Details * **Model Name**: `contextboxai/ViZipvoice` * **Framework**: PyTorch * **Language**: Vietnamese ## License This project is licensed under the Apache 2.0 License. ## Acknowledgements We would like to thank the Hugging Face community for their support. ``` -------------------------------- ### ViZipvoice Python Script Source: https://huggingface.co/contextboxai/ViZipvoice/commits/70503572b5202ef90278821bddd54f86eb3325fb?p=1 This script, vizipvoice.py, is the main entry point for the ViZipvoice text-to-speech system. It handles audio generation based on provided text and configuration. ```python import torch from transformers import AutoModelForTextToSpeech, AutoProcessor, pipeline def main(): model_id = "https://huggingface.co/contextboxai/ViZipvoice" processor = AutoProcessor.from_pretrained(model_id) model = AutoModelForTextToSpeech.from_pretrained(model_id) pipe = pipeline("text-to-speech", model=model, tokenizer=processor.tokenizer, device="cpu") text = "Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói." output = pipe(text) # The output is a dictionary containing the generated audio # You can save it to a file or play it directly # For example, to save to a WAV file: # import soundfile as sf # sf.write("output.wav", output["audio"], samplerate=output["sampling_rate"]) print("Audio generated successfully!") if __name__ == "__main__": main() ``` -------------------------------- ### CLI Inference with ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blob/03e26b4283e42a8927f0bd34613636c41c00a6a1/README.md Use the command-line interface for text-to-speech synthesis. Specify prompt audio, prompt text, input text, and output path. The CLI downloads the model by default; use --model-dir for local models. ```bash python3 -m zipvoice.bin.infer_vizipvoice \ --prompt-wav prompt.wav \ --prompt-text "Xin chào, đây là giọng mẫu của tôi." \ --text "ViZipVoice có thể tổng hợp giọng nói tiếng Việt từ một đoạn mẫu ngắn." \ --res-wav-path output.wav ``` -------------------------------- ### ViZipVoiceTTS Source: https://huggingface.co/contextboxai/ViZipvoice/commit/befd0e182594824474c5f2ee13ab1963101583aa Initializes the ViZipVoiceTTS wrapper. It downloads model files from Hugging Face by default, builds the ZipVoice model with the Vietnamese character tokenizer, and configures the inference environment. ```APIDOC ## ViZipVoiceTTS ### Description Initializes the ViZipVoiceTTS wrapper. It downloads model files from Hugging Face by default, builds the ZipVoice model with the Vietnamese character tokenizer, and configures the inference environment. ### Method __init__ ### Parameters #### Path Parameters - **repo_id** (str) - Optional - The Hugging Face repository ID for the model. Defaults to `DEFAULT_REPO_ID`. - **revision** (Optional[str]) - Optional - The specific model revision (branch or tag) to use. - **model_dir** (Optional[Union[str, Path]]) - Optional - Local directory containing model files. If not provided, files are downloaded. - **checkpoint_name** (str) - Optional - The name of the model checkpoint file. Defaults to `DEFAULT_CHECKPOINT_NAME`. - **vocoder_path** (Optional[Union[str, Path]]) - Optional - Path to a custom vocoder. - **device** (Optional[Union[str, torch.device]]) - Optional - The device to run inference on (e.g., 'cuda', 'cpu'). - **use_fp16** (bool) - Optional - Whether to use FP16 precision for inference (requires CUDA). Defaults to True. - **num_threads** (int) - Optional - The number of threads to use for PyTorch operations. Defaults to 1. ``` -------------------------------- ### Python Wrapper Source: https://huggingface.co/contextboxai/ViZipvoice/blob/b7f8b4605c3ab4ca42fd4c1a200ac114221ecdc0/README.md This snippet demonstrates how to use the ViZipVoice Python wrapper to synthesize speech. It requires a prompt audio file, prompt text, the text to synthesize, and an output path for the generated audio. ```APIDOC ## Python Wrapper ### Description Synthesize Vietnamese speech using the ViZipVoice Python wrapper. ### Method Python ### Usage ```python from zipvoice.vizipvoice import ViZipVoiceTTS tts = ViZipVoiceTTS() metrics = tts.synthesize( prompt_wav="prompt.wav", prompt_text="Xin chào, đây là giọng mẫu của tôi.", text="Đây là câu tiếng Việt được sinh bởi ViZipVoice.", output_path="output.wav", ) print(metrics) ``` ### Parameters * `prompt_wav` (string) - Required - Path to the prompt audio file. * `prompt_text` (string) - Required - The text corresponding to the prompt audio. * `text` (string) - Required - The text to synthesize into speech. * `output_path` (string) - Required - Path to save the synthesized audio file. ``` -------------------------------- ### Generate Speech with ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/1cdd6d455d27848ee6293831e26f2384ca9642ee/demo/metadata.json This snippet demonstrates how to use the ViZipvoice model to generate speech from text. It includes parameters for output file, prompt audio, prompt text, and various generation settings like seed, steps, guidance scale, and audio processing options. ```python from TTS.api import TTS # Get device device = "cuda" if torch.cuda.is_available() else "cpu" # Init TTS tts = TTS("tts_models/vi/contextbox/zipvoice", gpu=torch.cuda.is_available()) # Run TTS # Example 1: Generate speech from text tts.tts_to_file(text="Chiến tranh luôn là một chủ đề nặng nề, nhưng cũng rất cần được nhắc đến để con người hiểu rõ hơn giá trị của hòa bình. Khi một cuộc chiến xảy ra, những gì bị phá hủy không chỉ là nhà cửa, đường sá, trường học hay bệnh viện. Điều đau lòng nhất chính là sinh mạng con người, là những gia đình bị chia cắt, là những đứa trẻ phải lớn lên trong sợ hãi, và là những vùng đất từng yên bình bỗng trở nên hoang tàn.", speaker_wav="audio/Đinh-Quyết.mp3", file_path="demo_01_Đinh-Quyết.wav") # Example 2: Generate speech with more control tts.tts_to_file(text="Trong trang, việc ứng dụng công nghệ và chuyển đổi số đang là yếu tố chi phối các mô hình này.", speaker_wav="audio/Đinh-Quyết.mp3", file_path="demo_02_Đinh-Quyết.wav", seed=667, num_step=16, guidance_scale=1.0, speed=1.0, t_shift=0.5, split_sentences=True, crossfade_ms=80, silence_ms=180, fade_in_ms=20, fade_out_ms=80) ``` -------------------------------- ### ViZipvoice Python Script Source: https://huggingface.co/contextboxai/ViZipvoice/commits/1cdd6d455d27848ee6293831e26f2384ca9642ee?p=1 This script demonstrates how to use the ViZipvoice model for text-to-speech generation. It requires specific model files and configuration. ```python from transformers import AutoProcessor, AutoModelForTextToSpeech from scipy.io.wavfile import write as write_wav import torch processor = AutoProcessor.from_pretrained("contextboxai/ViZipvoice") model = AutoModelForTextToSpeech.from_pretrained("contextboxai/ViZipvoice") if model.can_generate() and torch.cuda.is_available(): model.to("cuda") inputs = processor(text="Xin chào, đây là một ví dụ về chuyển văn bản thành giọng nói.", return_tensors="pt") # Move inputs to GPU if available if torch.cuda.is_available(): inputs = inputs.to("cuda") # Ensure model is on CUDA model.to("cuda") with torch.no_grad(): speech = model.generate(**inputs) # Move speech to CPU for saving if it was on GPU if speech.is_cuda: speech = speech.cpu() # Save the audio to a file # The sampling rate is typically 16000 for this model, but it's good practice to check # if the model or processor provides it. # For ViZipvoice, the sampling rate is 16000 Hz. sampling_rate = 16000 write_wav("output.wav", sampling_rate, speech.numpy().squeeze()) print("Audio saved to output.wav") ``` -------------------------------- ### CLI for ViZipvoice Inference Source: https://huggingface.co/contextboxai/ViZipvoice/commit/f29fd21bd2cd0b50db12c88778822272a8a60870 Use the command-line interface to perform text-to-speech synthesis. Specify a prompt audio, prompt text, input text, and output path. ```bash python3 -m zipvoice.bin.infer_vizipvoice \ --prompt-wav prompt.wav \ --prompt-text "Xin chào, đây là giọng mẫu của tôi." \ --text "ViZipVoice có thể tổng hợp giọng nói tiếng Việt từ một đoạn mẫu ngắn." \ --res-wav-path output.wav ``` -------------------------------- ### CLI Inference Source: https://huggingface.co/contextboxai/ViZipvoice/blob/4d9765a6d79744fe64f7d68ff993795f74c2e8fa/README.md How to use the command-line interface for text-to-speech synthesis. ```APIDOC ## CLI ``` python3 -m zipvoice.bin.infer_vizipvoice \ --prompt-wav prompt.wav \ --prompt-text "Xin chào, đây là giọng mẫu của tôi." \ --text "ViZipVoice có thể tổng hợp giọng nói tiếng Việt từ một đoạn mẫu ngắn." \ --res-wav-path output.wav ``` The CLI downloads this model repo by default. Use `--model-dir models/ViZipvoice` after downloading files locally. ``` -------------------------------- ### CLI for ViZipVoice Inference Source: https://huggingface.co/contextboxai/ViZipvoice/blame/0d9339b43961a4000b9f27017975b97c154e1d90/README.md Use the command-line interface to synthesize speech from text using a prompt audio file. Specify input prompt audio, text, and output path. ```bash python3 -m zipvoice.bin.infer_vizipvoice \ --prompt-wav prompt.wav \ --prompt-text "Xin chào, đây là giọng mẫu của tôi." \ --text "ViZipVoice có thể tổng hợp giọng nói tiếng Việt từ một đoạn mẫu ngắn." \ --res-wav-path output.wav ``` -------------------------------- ### Model Configuration File Source: https://huggingface.co/contextboxai/ViZipvoice/commits/5a2eaf35fb2065c69c3f921312b3293a5f299b52?p=1 This JSON file contains the configuration parameters for the ViZipvoice model, including details about the model architecture, sampling rate, and other settings. ```json { "model_type": "ViZipvoice", "sampling_rate": 16000, "num_mels": 80, "num_heads": 8, "num_layers": 6, "dim": 512, "ffn_dim": 2048, "dropout": 0.1, "num_speakers": 10, "speaker_embedding_dim": 128 } ``` -------------------------------- ### Zero-shot TTS / Voice Cloning with pipeline Source: https://huggingface.co/contextboxai/ViZipvoice/commits/4f7cce6974b15a37fe31279679c2b04cecd62ff0 This snippet demonstrates zero-shot TTS and voice cloning using a reference audio file with the Hugging Face pipeline. ```python from transformers import pipeline # Load the ViZipvoice model synthesizer = pipeline("text-to-speech", model="contextboxai/ViZipvoice") # Synthesize speech using a reference audio file for voice cloning text = "Đây là giọng nói được tạo ra từ một mẫu âm thanh tham chiếu." reference_audio_path = "path/to/your/reference_audio.wav" speech = synthesizer(text, audio_path=reference_audio_path) # Save the synthesized speech sf.write("cloned_voice_output.wav", speech["audio"], speech["sampling_rate"]) ``` -------------------------------- ### Generate Speech with ViZipvoice Source: https://huggingface.co/contextboxai/ViZipvoice/blame/d3549bb534b1e3f3cf4e850934f11cbe6b704516/demo/metadata.json This snippet demonstrates how to use the ViZipvoice model to generate speech from text. It includes parameters for output file, prompt audio, text content, and various synthesis settings like seed, guidance scale, speed, and audio processing options. ```python from transformers import pipeline import torch pipe = pipeline( "audio-to-audio", model="contextboxai/ViZipvoice", device="cuda" if torch.cuda.is_available() else "cpu" ) output = pipe( "audio/Đinh-Quyết.mp3", prompt_text="Trong trang, việc ứng dụng công nghệ và chuyển đổi số đang là yếu tố chi phối các mô hình này.", text="Chiến tranh luôn là một chủ đề nặng nề, nhưng cũng rất cần được nhắc đến để con người hiểu rõ hơn giá trị của hòa bình. Khi một cuộc chiến xảy ra, những gì bị phá hủy không chỉ là nhà cửa, đường sá, trường học hay bệnh viện. Điều đau lòng nhất chính là sinh mạng con người, là những gia đình bị chia cắt, là những đứa trẻ phải lớn lên trong sợ hãi, và là những vùng đất từng yên bình bỗng trở nên hoang tàn.", output="demo_01_Đinh-Quyết.wav", seed=667, num_step=16, guidance_scale=1.0, speed=1.0, t_shift=0.5, split_sentences=True, crossfade_ms=80, silence_ms=180, fade_in_ms=20, fade_out_ms=80, ) print(output) ```