a
    g                     @   s^   d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	Z	e Z
e
dedddZdS )	    )FastAPIN)	BaseModel)AudioSegmentz/audio_texto)	audio_urlc           
   
      s  zt | }|jdkr|j}tdd}|| W d    n1 sF0    Y  td}|jddd t	
 }t	d(}||}|j|dd}W d    n1 s0    Y  td td d	|iW S d
diW S W n8 ty }	 zd
dt|	 iW  Y d }	~	S d }	~	0 0 d S )N   ztemp_audio.mp3wbztemp_audio.wavZwav)formatzes-ES)languageZtextoerrorz(No se pudo descargar el archivo de audiozError al procesar el archivo: )requestsgetstatus_codecontentopenwriter   Zfrom_mp3ZexportsrZ
RecognizerZ	AudioFilerecordZrecognize_googleosremove	Exceptionstr)
r   responseZaudio_contentfZaudioZ
recognizerZ
audio_fileZ
audio_dataZtexto_extraidoe r   (/var/www/html/texto_audio/audio_texto.pyconvertir_audio_texto
   s$    

(

,


r   )Zfastapir   r   Zspeech_recognitionr   Zpydanticr   Zpydubr   r   appr   r   r   r   r   r   r   <module>   s   