--- base_model: - k2-fsa/OmniVoice license: cc-by-nc-4.0 pipeline_tag: text-to-speech tags: - text-to-speech - speech-synthesis - zero-shot - multilingual - voice-cloning - voice-design - omnivoice - bf16 - bfloat16 - pytorch - cuda - audio - generative-audio library_name: omnivoice --- # OmniVoice BF16 This repository contains the BF16 converted OmniVoice model for PyTorch inference. **Converter / inference repository:** https://github.com/kawshikbuet17/OmniVoice-Model-Converter ## Requirements Install these packages in your Python environment: ```text omnivoice torch soundfile numpy ``` ## Basic Python Inference Prepare two local files before running: ```text ref_audio.wav ref_text.txt ``` ```python from pathlib import Path import numpy as np import soundfile as sf import torch from omnivoice import OmniVoice repo_id = "kawshikbuet17/OmniVoice-bf16" text = "আমি কৌশিকের কনভার্ট করা মডেল ব্যবহার করে এই অডিওটি তৈরি করছি।" ref_audio = "./ref_audio.wav" ref_text = Path("./ref_text.txt").read_text(encoding="utf-8").strip() out_wav = "./omnivoice_bf16_output.wav" model = OmniVoice.from_pretrained( repo_id, device_map="cuda:0", dtype=torch.float16, ) model.eval() if hasattr(model, "eval") else None with torch.inference_mode(): output = model.generate( text=text, language="Bengali", ref_audio=ref_audio, ref_text=ref_text, num_step=32, guidance_scale=2.0, speed=1.0, t_shift=0.1, denoise=True, postprocess_output=True, layer_penalty_factor=5.0, position_temperature=5.0, class_temperature=0.0, audio_chunk_duration=15.0, audio_chunk_threshold=30.0, ) if isinstance(output, dict): for key in ["audio", "audios", "wav", "wavs", "waveform", "samples"]: if key in output: output = output[key] break if isinstance(output, (tuple, list)): output = output[0] if isinstance(output, torch.Tensor): audio = output.detach().float().cpu().numpy() else: audio = np.asarray(output, dtype=np.float32) while audio.ndim > 1 and audio.shape[0] == 1: audio = audio[0] if audio.ndim == 2 and audio.shape[0] <= 8 and audio.shape[1] > audio.shape[0]: audio = audio.T audio = np.clip(audio, -1.0, 1.0) sample_rate = getattr(model, "sampling_rate", None) or getattr(model, "sample_rate", None) or 24000 sf.write(out_wav, audio, sample_rate) print(f"Saved: {out_wav}") ``` ## Notes - Use `device_map="cuda:0"` or `device_map="cuda:1"` based on your GPU. - Use `device_map="cpu"` only if GPU is not available. CPU inference can be slow. --- ## Prepared By Kawshik Kumar Paul Software Engineer | Researcher Department of Computer Science and Engineering (CSE) Bangladesh University of Engineering and Technology (BUET) Email: kawshikbuet17@gmail.com