o
    ˜Ujö  ã                   @  sL   d Z ddlmZ ddlZddlZej dd¡ ddlmZ G dd	„ d	ƒZ	dS )
u+  Local speech-to-text via faster-whisper.

Audio is transcribed on THIS machine (CPU or GPU) â€” it is never sent to a cloud speech service.
The model is loaded lazily on first use and reused. Small models (tiny.en/base.en) run fine on CPU
with int8 compute, keeping with the energy-efficiency goal.
é    )ÚannotationsNZKMP_DUPLICATE_LIB_OKZTRUEé   )ÚConfigc                   @  s(   e Zd Zddd„Zdd„ Zddd„ZdS )ÚTranscriberÚcfgr   c                 C  sB   |  dd¡| _|  dd¡| _|  dd¡| _|  dd¡| _d | _d S )	Nz	stt.modelzbase.enz
stt.deviceZcpuzstt.compute_typeZint8zstt.languageZen)ÚgetÚmodel_idÚdeviceÚcompute_typeÚlanguageÚ_model)Úselfr   © r   úSC:\Users\cheed\OneDrive\Desktop\Claude work\travel-insurance-agent\src\agent\stt.pyÚ__init__   s
   
zTranscriber.__init__c                 C  s2   | j d u rddlm} || j| j| jd�| _ | j S )Nr   )ÚWhisperModel)r	   r
   )r   Zfaster_whisperr   r   r	   r
   )r   r   r   r   r   Ú_load   s   
zTranscriber._loadÚaudio_bytesÚbytesÚreturnÚstrc                 C  s<   |   ¡ }|jt |¡| jdd�\}}d dd„ |D ƒ¡ ¡ S )zQTranscribe raw audio bytes (any ffmpeg-decodable format, e.g. webm/opus) to text.T)r   Z
vad_filterú c                 s  s   � | ]}|j  ¡ V  qd S )N)ÚtextÚstrip)Ú.0Úsegr   r   r   Ú	<genexpr>*   s   € z)Transcriber.transcribe.<locals>.<genexpr>N)r   Ú
transcribeÚioÚBytesIOr   Újoinr   )r   r   ZmodelÚsegmentsZ_infor   r   r   r   #   s
   
ÿzTranscriber.transcribeN)r   r   )r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r      s    
r   )
Ú__doc__Ú
__future__r   r   ÚosÚenvironÚ
setdefaultÚsettingsr   r   r   r   r   r   Ú<module>   s    