o
    lWiH                     @   sV  d dl Z d dlZd dlZd dlmZ ddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 e1ej2dZ3G dd dZ4G dd dZ5dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)RequestOptions)'convert_and_respect_annotation_metadata)construct_type)UnprocessableEntityError)0AudioWithTimestampsAndVoiceSegmentsResponseModel)DialogueInput)HttpValidationError)ModelSettingsResponseModel)%PronunciationDictionaryVersionLocator)>StreamingAudioChunkWithTimestampsAndVoiceSegmentsResponseModel   ):BodyTextToDialogueFullWithTimestampsApplyTextNormalization)UBodyTextToDialogueMultiVoiceStreamingV1TextToDialogueStreamPostApplyTextNormalization)FBodyTextToDialogueMultiVoiceV1TextToDialoguePostApplyTextNormalization)<BodyTextToDialogueStreamWithTimestampsApplyTextNormalization)(TextToDialogueConvertRequestOutputFormat)6TextToDialogueConvertWithTimestampsRequestOutputFormat)'TextToDialogueStreamRequestOutputFormat)5TextToDialogueStreamWithTimestampsRequestOutputFormat.c                   @   h  e Zd ZdefddZejdeeeeeedddej	e
 deje deje d	eje d
eje dejej	e  deje deje deje dejeeje   fddZejdeeeeeedddej	e
 deje deje d	eje d
eje dejej	e  deje deje deje dejeeje   fddZejdeeeeeedddej	e
 deje deje d	eje d
eje dejej	e  deje deje deje dejeeje   fddZdeeeeeedddej	e
 deje deje d	eje d
eje dejej	e  deje deje deje dee  fddZ!dS )RawTextToDialogueClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r%   j/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/text_to_dialogue/raw_client.py__init__3      
z RawTextToDialogueClient.__init__Noutput_formatmodel_idlanguage_codesettings!pronunciation_dictionary_locatorsseedapply_text_normalizationrequest_optionsinputsr*   r+   r,   r-   r.   r/   r0   r1   returnc       	         #       | j jjddd|it|tjt dd||t|tddt|tjt dd||dddit	d	 d
t
tjt  f fdd}
|
 V  W d   dS 1 sOw   Y  dS )u
  
        Converts a list of text and voice ID pairs into speech (dialogue) and returns audio.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueConvertRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueMultiVoiceV1TextToDialoguePostApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[HttpResponse[typing.Iterator[bytes]]]
            The generated audio file
        v1/text-to-dialoguePOSTr*   writeobject_
annotation	directionr2   r+   r,   r-   r.   r/   r0   content-typeapplication/jsonmethodparamsjsonheadersr1   omitr3   c               	         zKd j   krdk r*n nd urddnd} t dd  j| dD dW S     j d	krFtt jt	t
tt
  d
d  }W n ty^   t j t j jdw t j t j|d)N   ,  
chunk_size   c                 s       | ]}|V  qd S r    r%   .0_chunkr%   r%   r&   	<genexpr>       zCRawTextToDialogueClient.convert.<locals>._stream.<locals>.<genexpr>rH   responsedata  type_r9   rC   bodystatus_coderC   rX   rZ   getr   
iter_bytesreadr   dictrC   typingcastr   r   rB   r   r   text_chunk_size_response_json	_responser1   r%   r&   _stream   2   

z0RawTextToDialogueClient.convert.<locals>._streamNr"   httpx_clientstreamr
   r`   Sequencer   r   r   OMITr   Iteratorbytesr$   r2   r*   r+   r,   r-   r.   r/   r0   r1   rh   r%   rf   r&   convert6   >   7
"zRawTextToDialogueClient.convertc       	         #   r4   )u   
        Converts a list of text and voice ID pairs into speech (dialogue) and returns an audio stream.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueStreamRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueMultiVoiceStreamingV1TextToDialogueStreamPostApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.Iterator[HttpResponse[typing.Iterator[bytes]]]
            Streaming audio data
        v1/text-to-dialogue/streamr6   r*   r7   r8   r<   r=   r>   r?   r3   c               	      rE   )NrF   rG   rH   rI   c                 s   rJ   r    r%   rK   r%   r%   r&   rN     rO   zBRawTextToDialogueClient.stream.<locals>._stream.<locals>.<genexpr>rP   rQ   rT   rU   rW   rY   r[   rc   rf   r%   r&   rh      ri   z/RawTextToDialogueClient.stream.<locals>._streamNrj   rq   r%   rf   r&   rl      rs   zRawTextToDialogueClient.streamc       	         #   s    | j jjddd|it|tjt dd||t|tddt|tjt dd||dddi|	t	d	 d
t
tjt  f fdd}
|
 V  W d   dS 1 sNw   Y  dS )u  
        Converts a list of text and voice ID pairs into speech (dialogue) and returns a stream of JSON blobs containing audio as a base64 encoded string and timestamps

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueStreamWithTimestampsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueStreamWithTimestampsApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[HttpResponse[typing.Iterator[StreamingAudioChunkWithTimestampsAndVoiceSegmentsResponseModel]]]
            Stream of transcription chunks
        *v1/text-to-dialogue/stream/with-timestampsr6   r*   r7   r8   r<   r=   r>   r?   r3   c               	      s   z=d j   krdk rn n fdd} t |  dW S     j dkr8tt jttt	t 
 dd 
 }W n tyP   t j t j jd	w t j t j|d	)
NrF   rG   c               	   3   sV       D ]#} zt| dkrW qttttt| dV  W q ty(   Y qw d S Nr   rU   )	
iter_lineslenr`   ra   r   r   rB   loads	Exception_textrg   r%   r&   _iterq  s    
zNRawTextToDialogueClient.stream_with_timestamps.<locals>._stream.<locals>._iterrQ   rT   rU   rW   rY   )rZ   r   r^   r   r_   rC   r`   ra   r   r   rB   r   r   rb   r~   re   r}   r%   r&   rh   k  s.   

z?RawTextToDialogueClient.stream_with_timestamps.<locals>._streamN)r"   rk   rl   r
   r`   rm   r   r   r   rn   r   ro   r   rq   r%   r}   r&   stream_with_timestamps  sB   5
*"z.RawTextToDialogueClient.stream_with_timestampsc       	         C   s  | j jjddd|it|tjt dd||t|tddt|tjt dd||dddi|	t	d	}
z>d
|
j
  kr;dk rPn ntttt|
 d}t|
|dW S |
j
dkrhtt|
jtttt|
 dd|
 }W n ty   t|
j
t|
j|
jdw t|
j
t|
j|d)u
  
        Generate dialogue from text with precise character-level timing information for audio-text synchronization.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueConvertWithTimestampsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueFullWithTimestampsApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AudioWithTimestampsAndVoiceSegmentsResponseModel]
            Successful Response
        #v1/text-to-dialogue/with-timestampsr6   r*   r7   r8   r<   r=   r>   r?   rF   rG   rU   rQ   rT   rW   rY   )r"   rk   requestr
   r`   rm   r   r   r   rn   rZ   ra   r   r   rB   r   r   r_   rC   r   r   r   rb   r$   r2   r*   r+   r,   r-   r.   r/   r0   r1   rg   _datare   r%   r%   r&   convert_with_timestamps  sh   4

z/RawTextToDialogueClient.convert_with_timestamps)"__name__
__module____qualname__r   r'   
contextlibcontextmanagerrn   r`   rm   r   Optionalr   strr   r   intr   r	   ro   r   rp   rr   r   r   rl   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r   2   s   pp r   c                   @   r   )AsyncRawTextToDialogueClientr   c                C   r   r    r!   r#   r%   r%   r&   r'     r(   z%AsyncRawTextToDialogueClient.__init__Nr)   r2   r*   r+   r,   r-   r.   r/   r0   r1   r3   c       	              | j jjddd|it|tjt dd||t|tddt|tjt dd||dddit	d	4 I d
H " dt
tjt  f fdd}
|
 I d
H V  W d
  I d
H  d
S 1 I d
H s\w   Y  d
S )u
  
        Converts a list of text and voice ID pairs into speech (dialogue) and returns audio.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueConvertRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueMultiVoiceV1TextToDialoguePostApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]
            The generated audio file
        r5   r6   r*   r7   r8   r<   r=   r>   r?   Nr3   c               	         zNd j   krdk r+n nd urddnd} t dd  j| d2 dW S   I d H   j d	krJtt jt	t
tt
  d
d  }W n tyb   t j t j jdw t j t j|d)NrF   rG   rH   rI   c                 S     | z	3 d H W }|V  q6 d S r    r%   rK   r%   r%   r&   rN   b      zHAsyncRawTextToDialogueClient.convert.<locals>._stream.<locals>.<genexpr>rP   rQ   rT   rU   rW   rY   rZ   r\   r   aiter_bytesareadr   r_   rC   r`   ra   r   r   rB   r   r   rb   rc   rf   r%   r&   rh   \  6   

z5AsyncRawTextToDialogueClient.convert.<locals>._streamr"   rk   rl   r
   r`   rm   r   r   r   rn   r   AsyncIteratorrp   rq   r%   rf   r&   rr     >   7.z$AsyncRawTextToDialogueClient.convertc       	           r   )u  
        Converts a list of text and voice ID pairs into speech (dialogue) and returns an audio stream.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueStreamRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueMultiVoiceStreamingV1TextToDialogueStreamPostApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Returns
        -------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]
            Streaming audio data
        rt   r6   r*   r7   r8   r<   r=   r>   r?   Nr3   c               	      r   )NrF   rG   rH   rI   c                 S  r   r    r%   rK   r%   r%   r&   rN     r   zGAsyncRawTextToDialogueClient.stream.<locals>._stream.<locals>.<genexpr>rP   rQ   rT   rU   rW   rY   r   rc   rf   r%   r&   rh     r   z4AsyncRawTextToDialogueClient.stream.<locals>._streamr   rq   r%   rf   r&   rl   y  r   z#AsyncRawTextToDialogueClient.streamc       	           s   | j jjddd|it|tjt dd||t|tddt|tjt dd||dddi|	t	d	4 I d
H ! dt
tjt  f fdd}
|
 I d
H V  W d
  I d
H  d
S 1 I d
H s[w   Y  d
S )u"  
        Converts a list of text and voice ID pairs into speech (dialogue) and returns a stream of JSON blobs containing audio as a base64 encoded string and timestamps

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueStreamWithTimestampsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueStreamWithTimestampsApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[StreamingAudioChunkWithTimestampsAndVoiceSegmentsResponseModel]]]
            Stream of transcription chunks
        ru   r6   r*   r7   r8   r<   r=   r>   r?   Nr3   c               	      s   z@d j   krdk rn n fdd} t |  dW S   I d H   j dkr<tt jttt	t 
 dd 
 }W n tyT   t j t j jd	w t j t j|d	)
NrF   rG   c               	     s`      2 z'3 d H W } zt| dkrW qttttt| dV  W q ty,   Y qw 6 d S rv   )	aiter_linesrx   r`   ra   r   r   rB   ry   rz   r{   r}   r%   r&   r~   F  s"   
zSAsyncRawTextToDialogueClient.stream_with_timestamps.<locals>._stream.<locals>._iterrQ   rT   rU   rW   rY   )rZ   r   r   r   r_   rC   r`   ra   r   r   rB   r   r   rb   r   r}   r%   r&   rh   @  s0   

zDAsyncRawTextToDialogueClient.stream_with_timestamps.<locals>._stream)r"   rk   rl   r
   r`   rm   r   r   r   rn   r   r   r   rq   r%   r}   r&   r     sB   7*.z3AsyncRawTextToDialogueClient.stream_with_timestampsc       	            s   | j jjddd|it|tjt dd||t|tddt|tjt dd||dddi|	t	d	I d
H }
z>d|
j
  kr?dk rTn ntttt|
 d}t|
|dW S |
j
dkrltt|
jtttt|
 dd|
 }W n ty   t|
j
t|
j|
jdw t|
j
t|
j|d)u
  
        Generate dialogue from text with precise character-level timing information for audio-text synchronization.

        Parameters
        ----------
        inputs : typing.Sequence[DialogueInput]
            A list of dialogue inputs, each containing text and a voice ID which will be converted into speech.

        output_format : typing.Optional[TextToDialogueConvertWithTimestampsRequestOutputFormat]
            Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

        model_id : typing.Optional[str]
            Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property.

        language_code : typing.Optional[str]
            Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned.

        settings : typing.Optional[ModelSettingsResponseModel]
            Settings controlling the dialogue generation.

        pronunciation_dictionary_locators : typing.Optional[typing.Sequence[PronunciationDictionaryVersionLocator]]
            A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request

        seed : typing.Optional[int]
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295.

        apply_text_normalization : typing.Optional[BodyTextToDialogueFullWithTimestampsApplyTextNormalization]
            This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AudioWithTimestampsAndVoiceSegmentsResponseModel]
            Successful Response
        r   r6   r*   r7   r8   r<   r=   r>   r?   NrF   rG   rU   rQ   rT   rW   rY   )r"   rk   r   r
   r`   rm   r   r   r   rn   rZ   ra   r   r   rB   r   r   r_   rC   r   r   r   rb   r   r%   r%   r&   r   l  sj   4

z4AsyncRawTextToDialogueClient.convert_with_timestamps)"r   r   r   r   r'   r   asynccontextmanagerrn   r`   rm   r   r   r   r   r   r   r   r   r	   r   r   rp   rr   r   r   rl   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r     s   qq r   )6r   rB   r`   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.request_optionsr	   core.serializationr
   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   =types.audio_with_timestamps_and_voice_segments_response_modelr   types.dialogue_inputr   types.http_validation_errorr   #types.model_settings_response_modelr   .types.pronunciation_dictionary_version_locatorr   Mtypes.streaming_audio_chunk_with_timestamps_and_voice_segments_response_modelr   Itypes.body_text_to_dialogue_full_with_timestamps_apply_text_normalizationr   ktypes.body_text_to_dialogue_multi_voice_streaming_v_1_text_to_dialogue_stream_post_apply_text_normalizationr   Ztypes.body_text_to_dialogue_multi_voice_v_1_text_to_dialogue_post_apply_text_normalizationr   Ktypes.body_text_to_dialogue_stream_with_timestamps_apply_text_normalizationr   4types.text_to_dialogue_convert_request_output_formatr   Dtypes.text_to_dialogue_convert_with_timestamps_request_output_formatr   3types.text_to_dialogue_stream_request_output_formatr   Ctypes.text_to_dialogue_stream_with_timestamps_request_output_formatr   ra   Anyrn   r   r   r%   r%   r%   r&   <module>   s>      T