o
    i,                     @   s   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 eejdZG dd dZG dd dZdS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)RequestOptions)construct_type)BadRequestError   )"AudioGenerateRequestCallbackMethod)AudioGenerateRequestContainer)AudioGenerateRequestEncoding)AudioGenerateRequestModel.c                   @      e Zd ZdefddZejddddddddddd
dedej	e dej	e
 d	ej	e d
ej	ejeeje f  dej	e dej	e d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S )RawAudioClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   V/home/ubuntu/.local/lib/python3.10/site-packages/deepgram/speak/v1/audio/raw_client.py__init__      
zRawAudioClient.__init__N
callbackcallback_methodmip_opt_outtagbit_rate	containerencodingmodelsample_raterequest_optionstextr   r    r!   r"   r#   r$   r%   r&   r'   r(   returnc                #   s    | j jjd| j  jd||||||||	|
d	d|idditd dttjt	  f fd	d
}| V  W d   dS 1 sAw   Y  dS )a  
        Convert text into natural-sounding speech using Deepgram's TTS REST API

        Parameters
        ----------
        text : str
            The text content to be converted to speech

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[AudioGenerateRequestCallbackMethod]
            HTTP method by which the callback request will be made

        mip_opt_out : typing.Optional[bool]
            Opts out requests from the Deepgram Model Improvement Program. Refer to our Docs for pricing impacts before setting this to true. https://dpgr.am/deepgram-mip

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        bit_rate : typing.Optional[float]
            The bitrate of the audio in bits per second. Choose from predefined ranges or specific values based on the encoding type.

        container : typing.Optional[AudioGenerateRequestContainer]
            Container specifies the file format wrapper for the output audio. The available options depend on the encoding type.

        encoding : typing.Optional[AudioGenerateRequestEncoding]
            Encoding allows you to specify the expected encoding of your audio output

        model : typing.Optional[AudioGenerateRequestModel]
            AI model used to process submitted text

        sample_rate : typing.Optional[float]
            Sample Rate specifies the sample rate for the output audio. Based on the encoding, different sample rates are supported. For some encodings, the sample rate is not configurable

        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]]]
            Successful text-to-speech transformation
        v1/speakPOST	r   r    r!   r"   r#   r$   r%   r&   r'   r)   content-typeapplication/jsonbase_urlmethodparamsjsonheadersr(   omitr*   c               	      s   zMd 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rHtt jt	tj
ttj
  d	d
  }W n ty`   t j t j jdw t j t j|d)N   ,  
chunk_sizec                 s   s    | ]}|V  qd S r   r   .0_chunkr   r   r   	<genexpr>s   s    z;RawAudioClient.generate.<locals>._stream.<locals>.<genexpr>r9   responsedata  type_object_r5   bodystatus_coder5   rG   )rI   getr   
iter_bytesreadr   dictr5   typingcastAnyr
   r4   r   r   r)   _chunk_size_response_json	_responser(   r   r   _streamn   s2   

z(RawAudioClient.generate.<locals>._streamN)
r   httpx_clientstreamget_environmentbaseOMITr   rN   Iteratorbytesr   r)   r   r    r!   r"   r#   r$   r%   r&   r'   r(   rV   r   rT   r   generate   s4   ;

"zRawAudioClient.generate)__name__
__module____qualname__r   r   
contextlibcontextmanagerstrrN   Optionalr   boolUnionSequencefloatr   r   r   r	   r\   r   r]   r_   r   r   r   r   r      L    	
r   c                   @   r   )AsyncRawAudioClientr   c                C   r   r   r   r   r   r   r   r      r   zAsyncRawAudioClient.__init__Nr   r)   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r*   c                  s   | j jjd| j  jd||||||||	|
d	d|i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 sNw   Y  dS )a  
        Convert text into natural-sounding speech using Deepgram's TTS REST API

        Parameters
        ----------
        text : str
            The text content to be converted to speech

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[AudioGenerateRequestCallbackMethod]
            HTTP method by which the callback request will be made

        mip_opt_out : typing.Optional[bool]
            Opts out requests from the Deepgram Model Improvement Program. Refer to our Docs for pricing impacts before setting this to true. https://dpgr.am/deepgram-mip

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        bit_rate : typing.Optional[float]
            The bitrate of the audio in bits per second. Choose from predefined ranges or specific values based on the encoding type.

        container : typing.Optional[AudioGenerateRequestContainer]
            Container specifies the file format wrapper for the output audio. The available options depend on the encoding type.

        encoding : typing.Optional[AudioGenerateRequestEncoding]
            Encoding allows you to specify the expected encoding of your audio output

        model : typing.Optional[AudioGenerateRequestModel]
            AI model used to process submitted text

        sample_rate : typing.Optional[float]
            Sample Rate specifies the sample rate for the output audio. Based on the encoding, different sample rates are supported. For some encodings, the sample rate is not configurable

        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]]]
            Successful text-to-speech transformation
        r+   r,   r-   r)   r.   r/   r0   Nr*   c               	      s   zPd 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rLtt jt	tj
ttj
  d	d
  }W n tyd   t j t j jdw t j t j|d)Nr7   r8   r9   c                 S  s   | z	3 d H W }|V  q6 d S r   r   r:   r   r   r   r=      s    z@AsyncRawAudioClient.generate.<locals>._stream.<locals>.<genexpr>r>   r?   rB   rC   rF   rH   )rI   rJ   r   aiter_bytesareadr   rM   r5   rN   rO   rP   r
   r4   r   r   r)   rQ   rT   r   r   rV      s6   

z-AsyncRawAudioClient.generate.<locals>._stream)
r   rW   rX   rY   rZ   r[   r   rN   AsyncIteratorr]   r^   r   rT   r   r_      s4   ;
.zAsyncRawAudioClient.generate)r`   ra   rb   r   r   rc   asynccontextmanagerre   rN   rf   r   rg   rh   ri   rj   r   r   r   r	   ro   r   r]   r_   r   r   r   r   rl      rk   rl   )rc   rN   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.request_optionsr	   core.unchecked_base_modelr
   errors.bad_request_errorr   ,types.audio_generate_request_callback_methodr   &types.audio_generate_request_containerr   %types.audio_generate_request_encodingr   "types.audio_generate_request_modelr   rO   rP   r[   r   rl   r   r   r   r   <module>   s    u