o
    qmi                     @   s.  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* e +e j,dZ-G dd dZ.G dd dZ/dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)parse_obj_as)RequestOptions)'convert_and_respect_annotation_metadata)BadRequestError)ForbiddenError)InternalServerError)ServiceUnavailableError)TooManyRequestsError)UnprocessableEntityError)BulkJobCallbackParams)SpeechToTextJobParametersParams)BulkJobInitResponseV1)FilesDownloadResponse)FilesUploadResponse)JobStatusV1Response.c                
   @     e Zd ZdefddZedddedeje	 deje
 d	ee fd
dZdddedeje
 d	ee fddZddddedeje deje
 d	ee fddZdddedeje deje
 d	ee fddZdddedeje deje
 d	ee fddZdS )RawSpeechToTextJobClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r"   Z/home/ubuntu/.local/lib/python3.10/site-packages/sarvamai/speech_to_text_job/raw_client.py__init__      
z!RawSpeechToTextJobClient.__init__Ncallbackrequest_optionsjob_parametersr'   r(   returnc             
   C   sP  | j jjd| j  jdt|tddt|tdddddi|td}zd	|j	  kr-d
k rBn nt
ttt| d}t||dW S |j	dkrbtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd| }W n ty   t|j	t|j|jdw t|j	t|j|d)aO  
        Create a new speech to text bulk job and receive a job UUID and storage folder details for processing multiple audio files

        Parameters
        ----------
        job_parameters : SpeechToTextJobParametersParams
            Job Parameters for the bulk job

        callback : typing.Optional[BulkJobCallbackParams]
            Parameters for callback URL

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

        Returns
        -------
        HttpResponse[BulkJobInitResponseV1]
            Successful Response
        speech-to-text/job/v1POSTwriteobject_
annotation	directionr)   r'   content-typeapplication/jsonbase_urlmethodjsonheadersr(   omit   ,  type_r/   responsedata  r9   body          status_coder9   rD   )r   httpx_clientrequestget_environmentbaser   r   r   OMITrK   typingcastr   r
   r8   r   r   dictr9   OptionalAnyr   r   r   r   r   r   r   textr!   r)   r'   r(   	_response_data_response_jsonr"   r"   r#   
initialise"   s   
	






















z#RawSpeechToTextJobClient.initialiser(   job_idc             	   C   s6  | j jjdt| d| j  jd|d}zd|j  kr!dk r6n ntt	t
t	| d}t||dW S |jd	krVtt|jttjtj t
tjtj | dd
|jdkrvtt|jttjtj t
tjtj | dd
|jdkrtt|jttjtj t
tjtj | dd
|jdkrtt|jttjtj t
tjtj | dd
|jdkrtt|jttjtj t
tjtj | dd
|jdkrtt|jttjtj t
tjtj | dd
| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Retrieve the current status and details of a speech to text bulk job, including progress and file-level information.

        **Rate Limiting Best Practice:** To prevent rate limit errors and ensure optimal server performance, we recommend implementing a minimum 5-millisecond delay between consecutive status polling requests. This helps maintain system stability while still providing timely status updates.

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

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

        Returns
        -------
        HttpResponse[JobStatusV1Response]
            Successful Response
        speech-to-text/job/v1//statusGETr6   r7   r(   r;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   r   rL   rM   r	   rN   rO   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   r!   r]   r(   rX   rY   rZ   r"   r"   r#   
get_status   s   
























z#RawSpeechToTextJobClient.get_statusptu_idr(   rf   c             	   C   s<  | j jjdt| d| j  jdd|i|d}zd|j  kr$dk r9n ntt	t
t	| d}t||d	W S |jd
krYtt|jttjtj t
tjtj | dd|jdkrytt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Start processing a speech to text bulk job after all audio files have been uploaded

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

        ptu_id : typing.Optional[int]

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

        Returns
        -------
        HttpResponse[JobStatusV1Response]
            Successful Response
        r^   /startr,   rf   r6   r7   paramsr(   r;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   rb   r!   r]   rf   r(   rX   rY   rZ   r"   r"   r#   start  s   
	























zRawSpeechToTextJobClient.startfilesc             	   C   :  | j jjd| j  jd||dddi|td}zd|j  kr#dk r8n ntt	t
t	| d	}t||d
W S |jdkrXtt|jttjtj t
tjtj | d	d|jdkrxtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Generate presigned upload URLs for audio files that will be processed in a speech to text bulk job

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        HttpResponse[FilesUploadResponse]
            Successful Response
        "speech-to-text/job/v1/upload-filesr,   r]   rl   r3   r4   r5   r;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   )r   rL   rM   rN   rO   rP   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   r!   r]   rl   r(   rX   rY   rZ   r"   r"   r#   get_upload_links~     
























z)RawSpeechToTextJobClient.get_upload_linksc             	   C   rm   )a  
        Generate presigned download URLs for the transcription output files of a completed speech to text bulk job

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        HttpResponse[FilesDownloadResponse]
            Successful Response
        $speech-to-text/job/v1/download-filesr,   ro   r3   r4   r5   r;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   )r   rL   rM   rN   rO   rP   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   rp   r"   r"   r#   get_download_links  rr   z+RawSpeechToTextJobClient.get_download_links)__name__
__module____qualname__r   r$   rP   r   rQ   rT   r   r   r   r   r[   strr   rd   intrk   Sequencer   rq   r   rt   r"   r"   r"   r#   r      h    
~
p
t
tr   c                
   @   r   )AsyncRawSpeechToTextJobClientr   c                C   r   r   r   r    r"   r"   r#   r$   f  r%   z&AsyncRawSpeechToTextJobClient.__init__Nr&   r)   r'   r(   r*   c             
      sX  | j jjd| j  jdt|tddt|tdddddi|tdI d	H }zd
|j	  kr1dk rFn nt
ttt| d}t||dW S |j	dkrftt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd|j	dkrtt|jt
t
jt
j tt
jt
j | dd| }W n ty    t|j	t|j|jdw t|j	t|j|d)aT  
        Create a new speech to text bulk job and receive a job UUID and storage folder details for processing multiple audio files

        Parameters
        ----------
        job_parameters : SpeechToTextJobParametersParams
            Job Parameters for the bulk job

        callback : typing.Optional[BulkJobCallbackParams]
            Parameters for callback URL

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

        Returns
        -------
        AsyncHttpResponse[BulkJobInitResponseV1]
            Successful Response
        r+   r,   r-   r.   r2   r3   r4   r5   Nr;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   )r   rL   rM   rN   rO   r   r   r   rP   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   rW   r"   r"   r#   r[   i  s   
	






















z(AsyncRawSpeechToTextJobClient.initialiser\   r]   c             	      s>  | j jjdt| d| j  jd|dI dH }zd|j  kr%dk r:n ntt	t
t	| d}t||d	W S |jd
krZtt|jttjtj t
tjtj | dd|jdkrztt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Retrieve the current status and details of a speech to text bulk job, including progress and file-level information.

        **Rate Limiting Best Practice:** To prevent rate limit errors and ensure optimal server performance, we recommend implementing a minimum 5-millisecond delay between consecutive status polling requests. This helps maintain system stability while still providing timely status updates.

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

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

        Returns
        -------
        AsyncHttpResponse[JobStatusV1Response]
            Successful Response
        r^   r_   r`   ra   Nr;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   r   rL   rM   r	   rN   rO   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   rc   r"   r"   r#   rd     s   
























z(AsyncRawSpeechToTextJobClient.get_statusre   rf   c             	      sD  | j jjdt| d| j  jdd|i|dI dH }zd|j  kr(dk r=n ntt	t
t	| d	}t||d
W S |jdkr]tt|jttjtj t
tjtj | d	d|jdkr}tt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d|jdkrtt|jttjtj t
tjtj | d	d| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Start processing a speech to text bulk job after all audio files have been uploaded

        Parameters
        ----------
        job_id : str
            The unique identifier of the job

        ptu_id : typing.Optional[int]

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

        Returns
        -------
        AsyncHttpResponse[JobStatusV1Response]
            Successful Response
        r^   rg   r,   rf   rh   Nr;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   r}   rj   r"   r"   r#   rk   R  s   
	























z#AsyncRawSpeechToTextJobClient.startrl   c             	      B  | j jjd| j  jd||dddi|tdI dH }zd|j  kr'd	k r<n ntt	t
t	| d
}t||dW S |jdkr\tt|jttjtj t
tjtj | d
d|jdkr|tt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Generate presigned upload URLs for audio files that will be processed in a speech to text bulk job

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        AsyncHttpResponse[FilesUploadResponse]
            Successful Response
        rn   r,   ro   r3   r4   r5   Nr;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   )r   rL   rM   rN   rO   rP   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   rp   r"   r"   r#   rq        
























z.AsyncRawSpeechToTextJobClient.get_upload_linksc             	      r~   )a  
        Generate presigned download URLs for the transcription output files of a completed speech to text bulk job

        Parameters
        ----------
        job_id : str

        files : typing.Sequence[str]

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

        Returns
        -------
        AsyncHttpResponse[FilesDownloadResponse]
            Successful Response
        rs   r,   ro   r3   r4   r5   Nr;   r<   r=   r?   rB   rC   rE   rF   rG   rH   rI   rJ   )r   rL   rM   rN   rO   rP   rK   rQ   rR   r   r
   r8   r   r   rS   r9   rT   rU   r   r   r   r   r   r   r   rV   rp   r"   r"   r#   rt   8  r   z0AsyncRawSpeechToTextJobClient.get_download_links)ru   rv   rw   r   r$   rP   r   rQ   rT   r   r   r   r   r[   rx   r   rd   ry   rk   rz   r   rq   r   rt   r"   r"   r"   r#   r|   e  r{   r|   )0rQ   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.pydantic_utilitiesr
   core.request_optionsr   core.serializationr   errors.bad_request_errorr   errors.forbidden_errorr   errors.internal_server_errorr    errors.service_unavailable_errorr   errors.too_many_requests_errorr   !errors.unprocessable_entity_errorr   requests.bulk_job_callbackr   &requests.speech_to_text_job_parametersr    types.bulk_job_init_response_v_1r   types.files_download_responser   types.files_upload_responser   types.job_status_v_1_responser   rR   rU   rP   r   r|   r"   r"   r"   r#   <module>   s8       K