o
    Ih7                  
   @   s   d dl mZmZmZmZmZ d dlZd dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlZdZdZdd
ededefddZd
ededededef
ddZdS )    )FastAPIFormDependsHTTPExceptionRequestN)FileResponse)get_db)Session)UserZ3sk_e6d81a278349db89d1529ae70c06c75b52315a409db36063zhttps://api.elevenlabs.ioojNjxYKrSUDwsRrANSYctextvoice_idreturnc                 C   sd   t  d| }tddd}| ddddd	}tj|||d
}|jdkr&|jS td|j d|j )Nz/v1/text-to-speech/zapplication/json	audio/wav)z
xi-api-keyzContent-TypeZAcceptZeleven_monolingual_v1g      ?g      ?)Z	stabilityZsimilarity_boost)r   Zmodel_idZvoice_settings)jsonheaders   zError: z - )BASE_URLELEVENLABS_API_KEYrequestspoststatus_codecontent	Exceptionr   )r   r   urlr   payloadresponse r   ?/var/www/html/vive_backend/app/controllers/elevenlabs_client.pygenerate_voice   s   
r   typecurrent_userdbrequestc           	      C   sn   |  dkr	d}nd}t| |d}tjddd}|| |j}W d    n1 s+w   Y  t|dd	d
S )NZmaler   ZP7vsEyTOpZ6YUTulin8m)r   Fz.wav)deletesuffixr   zcloned_output.wav)
media_typefilename)lowerr   tempfileNamedTemporaryFilewritenamer   )	r   r    r!   r"   r#   r   Zaudio_bytestmpZtmp_pathr   r   r   clone_fixed"   s   
r.   )r   )fastapir   r   r   r   r   r   osfastapi.responsesr   app.databaser   sqlalchemy.ormr	   
app.modelsr
   r)   r   r   strbytesr   r.   r   r   r   r   <module>   s    "