U
    j=                     @  sx   d dl mZ d dlmZ d dlZd dlmZmZ dZG dd de	Z
ddd	d
ddddddddZdddddZdS )    )annotations)OptionalN)Settingsget_settingsi  @c                   @  s   e Zd ZdS )AudioTranscriptionErrorN)__name__
__module____qualname__ r
   r
   )/var/www/calcoee/app/audio_transcriber.pyr      s   r   es)languagesettingsbytesstrzOptional[str]zOptional[Settings])audio_bytes	file_namecontent_typer   r   returnc                 C  s   |pt  }|jstd| s$tdt| tkr8tdtjddd|j i|jt|ddd	|pdd
| |pldfidd}|j	dkrtd|j
 | ddpd}d| }|std|S )Nz1Configure MISTRAL_API_KEY para transcribir audio.z%No se recibio audio para transcribir.z#El audio supera el limite de 20 MB.z.https://api.mistral.ai/v1/audio/transcriptionsAuthorizationzBearer 0)modelr   Ztemperaturefilezdictado.webmz
audio/webmx   )headersdatafilestimeouti  z&Mistral no pudo transcribir el audio: text  z%Mistral no devolvio texto transcrito.)r   Zmistral_api_keyr   lenMAX_AUDIO_BYTEShttpxpostZmistral_transcription_model_normalize_languagestatus_coder   jsongetjoinsplit)r   r   r   r   r   responser   
normalizedr
   r
   r   transcribe_audio_bytes   s:    

r-   )r   r   c                 C  s   | sdS |  dd  pdS )Nr   -r   )r*   lower)r   r
   r
   r   r%   @   s    r%   )
__future__r   typingr   r#   Z
app.configr   r   r"   RuntimeErrorr   r-   r%   r
   r
   r
   r   <module>   s   	/