o
    i                     @   sN   d dl Z d dlZd dlmZ ddlmZ G dd dZddd	Zdd
dZdS )    N)hf_hub_download   )KittenTTS_1_Onnxc                   @   s:   e Zd ZdZdddZdd	d
ZdddZedd ZdS )	KittenTTSz2Main KittenTTS class for text-to-speech synthesis.KittenML/kitten-tts-nano-0.8Nc                 C   s*   d|vr
d| }n|}t ||d| _dS )zInitialize KittenTTS with a model from Hugging Face.
        
        Args:
            model_name: Hugging Face repository ID or model name
            cache_dir: Directory to cache downloaded files
        /z	KittenML/repo_id	cache_dirN)download_from_huggingfacemodel)self
model_namer
   r	    r   G/home/ubuntu/.local/lib/python3.10/site-packages/kittentts/get_model.py__init__
   s   zKittenTTS.__init__expr-voice-5-m      ?Fc                 C   s"   t d|  | jj||||dS )a  Generate audio from text.
        
        Args:
            text: Input text to synthesize
            voice: Voice to use for synthesis
            speed: Speech speed (1.0 = normal)
            
        Returns:
            Audio data as numpy array
        zGenerating audio for text: )voicespeed
clean_text)printr   generate)r   textr   r   r   r   r   r   r      s   zKittenTTS.generate]  c                 C   s   | j j|||||dS )a2  Generate audio from text and save to file.
        
        Args:
            text: Input text to synthesize
            output_path: Path to save the audio file
            voice: Voice to use for synthesis
            speed: Speech speed (1.0 = normal)
            sample_rate: Audio sample rate
        )r   r   sample_rate)r   generate_to_file)r   r   output_pathr   r   r   r   r   r   r   (   s   
zKittenTTS.generate_to_filec                 C   s   | j jS )zGet list of available voices.)r   all_voice_names)r   r   r   r   available_voices4   s   zKittenTTS.available_voices)r   N)r   r   F)r   r   r   )	__name__
__module____qualname____doc__r   r   r   propertyr   r   r   r   r   r      s    


r   KittenML/kitten-tts-nano-0.1c                 C   s   t | d|d}t|d}t|}W d   n1 sw   Y  |ddvr,tdt | |d |d}t | |d	 |d}t|||d
i |di d}|S )zDownload model files from Hugging Face repository.
    
    Args:
        repo_id: Hugging Face repository ID
        cache_dir: Directory to cache downloaded files
        
    Returns:
        KittenTTS_1_Onnx: Instantiated model ready for use
    zconfig.json)r	   filenamer
   rNtype)ONNX1ONNX2zUnsupported model type.
model_filevoicesspeed_priorsvoice_aliases)
model_pathvoices_pathr-   r.   )r   openjsonloadget
ValueErrorr   )r	   r
   config_pathfconfigr/   r0   r   r   r   r   r   :   s,    r   c                 C   s
   t | |S )zCGet a KittenTTS model (legacy function for backward compatibility).)r   r   r   r   r   	get_modele   s   
r9   )r%   N)	r2   oshuggingface_hubr   
onnx_modelr   r   r   r9   r   r   r   r   <module>   s    
3+