
    d|i}                     d    d dl Z d dlZd dlZddlmZ  ej        e          Z G d d          ZdS )    N   )AuthServicec                   (    e Zd Zd ZdededefdZdS )TranscriptionServicec                 ^    t          j        d          | _        t                      | _        d S )NTRANSCRIPTION_API_URL)osgetenvtranscription_urlr   auth_service)selfs    C:\Users\Dell Inspiron 16\Desktop\tws\github tws\Agrota\back-agrota-powerbi\mcp-client-agrota\app\services\transcription_service.py__init__zTranscriptionService.__init__
   s'    !#+B!C!C'MM    
audio_datafilenamereturnc                 0  K   | j         st          d          | j                                         d{V }dd| i}d||dfi}	 t	          j        d          4 d{V }t                              d	| j                     |                    | j         ||
           d{V }|j	        dk    r>t          
                    d|j	         d|j                    |                                 |                                }|                    dd          }	t                              d|	dd          d           |	cddd          d{V  S # 1 d{V swxY w Y   dS # t          $ r#}
t          
                    d|
             d}
~
ww xY w)zITranscribes the provided audio bytes using the LHIA AI Transcription API.z$TRANSCRIPTION_API_URL not configuredNAuthorizationzBearer filez
audio/mpegg      N@)timeoutu&   🎙️ Enviando audio a transcribir: )headersfiles   u   ❌ Transcription API Error z: transcripcion u   📝 Transcripción recibida: 2   z...u    ❌ Error during transcription: )r   
ValueErrorr   	get_tokenhttpxAsyncClientloggerinfopoststatus_codeerrortextraise_for_statusjsonget	Exception)r   r   r   tokenr   r   clientresponsedatatranscriptiones              r   transcribe_audioz%TranscriptionService.transcribe_audio   s     % 	ECDDD'1133333333"$5e$5$56 	
	(666 % % % % % % %&]TE[]]^^^!'*G5 "- " "       '3..LL^x7K^^x}^^   --///}} $" = =T]3B3=OTTTUUU$% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %"  	 	 	LL?A??@@@	s=   E( "C EE( 
EE( "E#E( (
F2FFN)__name__
__module____qualname__r   bytesstrr2    r   r   r   r   	   sL        * * *( (# (# ( ( ( ( ( (r   r   )	r	   r    loggingr   r   	getLoggerr3   r"   r   r8   r   r   <module>r;      sv    				   % % % % % %		8	$	$- - - - - - - - - -r   