
    6FiG                     4   d dl mZ d dlmZ d dlmZ d dlmZ d dlZ eej	        
                    ej	                            ej	                            ej	                            e                              dd                      G d	 d
          ZdS )    )BytesIO)
ElevenLabs)load_dotenv)ELEVENLABS_MODEL_IDNconfigz.env)dotenv_pathc                       e Zd Zd Zd ZdS )ElevenLabsTTSc                    t           j                            d          | _        | j        st	          d          	 t          | j                  | _        d S # t          $ r$}t          dt          |                     d }~ww xY w)NELEVENLABS_API_KEYz6ELEVENLABS_API_KEY not found in environment variables.)api_keyz(Failed to initialize ElevenLabs client: )
osenvirongetr   
ValueErrorr   client	ExceptionRuntimeErrorstr)selfes     =D:\xampp\htdocs\new-grp\engine\services\tts\elevenlabs_tts.py__init__zElevenLabsTTS.__init__
   s    z~~&:;;| 	WUVVV	T$T\:::DKKK 	T 	T 	TR#a&&RRSSS	Ts   A 
B"BBc                    t          |t                    st          d          |                    d          }|                    d          }|r|st	          d          	 | j        j                            ||t          d          }t                      }|D ]}|
                    |           |                    d           |S # t          $ r$}t          dt          |                     d }~ww xY w)	Nz9Input must be a dictionary containing 'text' and 'voice'.textvoicez7Missing required 'text' or 'voice' field in input data.mp3_44100_128)r   voice_idmodel_idoutput_formatr   z"Text-to-Speech conversion failed: )
isinstancedict	TypeErrorr   r   r   text_to_speechconvertr   r   writeseekr   r   r   )r   datar   r   audio_generatorbufferchunkr   s           r   r$   zElevenLabsTTS.text_to_speech   s   $%% 	YWXXXxx!! 	X5 	XVWWW	N"k8@@,-	 A  O YYF( $ $U####KKNNNM 	N 	N 	NLCFFLLMMM	Ns   #A&C
 

C8C33C8N)__name__
__module____qualname__r   r$        r   r
   r
   	   s:        T T TN N N N Nr0   r
   )ior   elevenlabs.clientr   dotenvr   config.constantsr   r   pathjoindirname__file__r
   r/   r0   r   <module>r9      s          ( ( ( ( ( (       0 0 0 0 0 0 				 RW__RW__RW__U]E^E^5_5_%`%`bjlrss t t t t#N #N #N #N #N #N #N #N #N #Nr0   