o
    ZAkjx	                     @  s   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ed Ze	dd	G d
d dZe	dd	G dd dZG dd deZG dd deZdS )z?Contratos STT/TTS independientes del proveedor (cloud o local).    )annotations)ABCabstractmethod)AsyncIterator)	dataclass)Literal)mulawlinear16T)frozenc                   @  s6   e Zd ZU dZdZded< dZded< dZded	< d
S )AudioFormatu,   Formato telefónico por defecto: 8 kHz mono.r   AudioEncodingencodingi@  intsample_rate_hz   channelsN)__name__
__module____qualname____doc__r   __annotations__r   r    r   r   9/var/www/html/bot-asterisk-ari/backend/voice/protocols.pyr      s
   
 r   c                   @  s.   e Zd ZU ded< dZded< dZded< dS )	TranscriptResultstrtextTboolis_finalNzfloat | None
confidence)r   r   r   r   r   r   r   r   r   r   r      s   
 r   c                   @  sL   e Zd ZU dZded< eddddddZddddddZdddZdS )SpeechToTextu   Transcribe audio del cliente → texto.

    Implementaciones: ``voice.stt.google_stt.GoogleSpeechToText``,
    ``voice.stt.local_stt.LocalSpeechToText`` (futuro).
    r   provider_nameNaudio_formatlanguage_codeaudiobytesr"   AudioFormat | Noner#   
str | Nonereturnr   c                     dS )z'Reconoce un utterance completo (batch).Nr   )selfr$   r"   r#   r   r   r   	recognize&       zSpeechToText.recognizechunksAsyncIterator[bytes]AsyncIterator[TranscriptResult]c                C sN   t  }|2 z3 dH W }|| q6 |r%| jt|||dI dH V  dS dS )z>Streaming opcional; por defecto concatena y usa ``recognize``.Nr!   )	bytearrayextendr+   r%   )r*   r-   r"   r#   bufferchunkr   r   r   stream_recognize0   s   zSpeechToText.stream_recognizeNonec                      d S Nr   r*   r   r   r   closeB      zSpeechToText.close)r$   r%   r"   r&   r#   r'   r(   r   )r-   r.   r"   r&   r#   r'   r(   r/   r(   r5   )	r   r   r   r   r   r   r+   r4   r9   r   r   r   r   r      s   
 r   c                   @  s<   e Zd ZU dZded< edddddddZdddZdS )TextToSpeechu   Sintetiza texto del bot → audio PCM/μ-law para RTP.

    Implementaciones: ``voice.tts.google_tts.GoogleTextToSpeech``,
    ``voice.tts.elevenlabs_tts.ElevenLabsTextToSpeech``,
    ``voice.tts.local_tts.LocalTextToSpeech`` (futuro).
    r   r    N)r"   voicer#   r   r"   r&   r=   r'   r#   r(   r%   c                  r)   )u?   Devuelve audio en el encoding pedidos (μ-law o PCM 16-bit LE).Nr   )r*   r   r"   r=   r#   r   r   r   
synthesizeP   r,   zTextToSpeech.synthesizer5   c                   r6   r7   r   r8   r   r   r   r9   [   r:   zTextToSpeech.close)
r   r   r"   r&   r=   r'   r#   r'   r(   r%   r;   )r   r   r   r   r   r   r>   r9   r   r   r   r   r<   F   s   
 
r<   N)r   
__future__r   abcr   r   collections.abcr   dataclassesr   typingr   r   r   r   r   r<   r   r   r   r   <module>   s    )