CoolFace
Apppublic

adityabanerjee/voxcpm2-studio

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes
app.cpython-310.pyc52 linesDownload Raw Back to __pycache__
1o

2��wj��@sddlZej�dd�ej�dd�ddlZddlZddlZddlZ	ddl3Z4ddlZddlm
Z
dZdZd	Ze
jed5d6dd�Zefd
ededeefdd�Z					dRd
edededBdedededefdd�Zejed�					dSd
edededBdedededefdd ��Zd!Zejejjd"d#�ed$���Ze� d%�e�!���ej"d&d'��)ej#d(d)d*d+d,�Z$ej#d-dd.�Z%ej&d/d0d1d2gd3�Z'ej(d4d5d6�Z)Wd�n1s�wYej"d7d'��Cej&d8d0d9�Z*ej+d:d7d;��$ej,d<d=dd>d?d@�Z-ej,dAdBddCdDd@�Z.ej/dddEdF�Z0Wd�n	1�swYWd�n	1�s'wYWd�n	1�s7wYe)j1ee$e%e'e-e.e0ge*dGdCdH�ej2dIgdJgdKgge$ge*edLdMdN�Wd�n	1�siwYe3dOk�rej4dCdP�j5dLdQ�dSdS)T�NZPYTORCH_CUDA_ALLOC_CONFzexpandable_segments:TrueZTOKENIZERS_PARALLELISMZfalse)�VoxCPMzopenbmb/VoxCPM2i�iFZcuda)Z
load_denoiser�optimizeZdevice�text�	max_chars�returncCs�ddl}|�d|���}g}d}|D](}|��}|sq|r1t|�t|�d|kr1|�|�|}q|�d|����}q|rB|�|�|S)zASplit long narration at sentence boundaries for stable synthesis.rNu(?<=[.!?。!?])\s*��� )�re�split�strip�len�append)rrr8Z	sentences�chunksZcurrentZsentence�r�hf_space_voxcpm2/app.py�9split_texts1011rr�@�12�*�voice_description�reference_audio�	cfg_value�inference_timesteps�seedcOs0tdtdtdt|p13d�dt|�d���S)zBEstimate ZeroGPU reservation from text length and diffusion steps.���-�#rg���Q��?�)�min�max�intr
)rrrrrr�args�kwargsrrr�estimate_gpu_seconds1s0r$)Zduration�,A warm, confident narrator with clear pacingcCs�d�|pd���}|st�d��t|�tkrt�dt�d���t|�}t|�}t|�}d|kr5dks;nt�d��d	|krEd14ksKnt�d��t|�}g}t	|�D]2\}	}15|16}|sk|�17�rkd|�18��d
|19��}tj||pqd||ddd||	d�}|�
tj|tjd��qU|s�t�d��tjttjjd�tjd�}
g}t	|�D]\}	}|	r�|�
|
�|�
|�q�t�|�}tjddd�}|��tj|j|tjjdd�|jS)a�Generate 48 kHz speech with VoxCPM2.20 21    Args:22        text: Narration to synthesize in any VoxCPM2-supported language.23        voice_description: Natural-language voice style used without reference audio.24        reference_audio: Optional short WAV recording for voice cloning.25        cfg_value: Guidance strength, normally between 1.5 and 3.0.26        inference_timesteps: Diffusion steps; higher can improve quality but costs time.27        seed: Reproducibility seed.28    r	rzEnter text to synthesize.zText is limited to z characters per request.��?�@z CFG must be between 1.0 and 4.0.��z)Inference steps must be between 4 and 20.�(�)NTF)rZreference_wav_pathrr�	normalizeZdenoiseZ
retry_badcaser)ZdtypezVoxCPM2 did not produce audio.g29ףp=30�?z.wav)�delete�suffixZPCM_16)Zsubtype)�joinr�gr�Errorr
�MAX_TEXT_CHARS�floatr!r�	enumerater�model�generater�npZasarrayZfloat32ZzerosZ	tts_modelZsample_rateZconcatenate�tempfileZNamedTemporaryFile�close�sf�write�name)rrrrrrZcleanedrZ	generated�index�chunkZ
designed_textZwav�pause�piecesZfull_wav�outputrrr�31synthesize?sT323334�35363738rBz�39.gradio-container { max-width: 1040px !important; margin: auto !important; }40.hero { text-align: center; padding: 1rem 0 .25rem; }41.hero h1 { font-size: 2.3rem; margin-bottom: .35rem; }42.dark .gradio-container { color: var(--body-text-color); }43Zindigo)Zprimary_hue)ZthemeZcssu�<div class='hero'><h1>🎙️ VoxCPM2 Studio</h1><p>Multilingual 48 kHz speech, voice design, and optional voice cloning.</p></div>r)ZscaleZ	Narration��uKType narration in English, Hindi, Chinese, or another supported language…)�label�linesZ	max_linesZplaceholderzVoice design)rE�valuezReference voice (optional)�filepathZuploadZ44microphone)rE�typeZsourceszGenerate speechZprimary)Zvariant�zGenerated 48 kHz speech)rErIzAdvanced settings)�openr&r'g�������?zCFG guidance)rG�steprEr(r)rzInference stepsZSeed)rGZ	precisionrEZtts)�fn�inputs�outputsZapi_nameZconcurrency_limitz[VoxCPM2 brings multilingual speech and expressive voice design to open-source applications.u�नमस्ते! यह एक स्वाभाविक और स्पष्ट हिंदी आवाज़ का उदाहरण है।u-你好,欢迎体验多语言语音合成。TZlazy)ZexamplesrNrOrMZcache_examplesZ45cache_mode�__main__)Zdefault_concurrency_limit)Z46mcp_server)rNrrr)r%Nrrr)6�os�environ�47setdefault�spacesZgradior0Znumpyr7Z	soundfiler:r8ZtorchZvoxcpmrZMODEL_IDr2ZMAX_CHUNK_CHARSZfrom_pretrainedr5�strr!�listrr3r$ZGPUrBZCSSZBlocksZthemesZSoftZdemoZHTMLZRowZColumnZTextboxrrZAudiorZButtonr6Zoutput_audioZ	AccordionZSliderZcfgZsteps�NumberrZclickZExamples�__name__�queueZlaunchrrrr�<module>s���������	48�49��������B�50��51�����������521�