o
    êis                     @   s\   d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
 G dd dZG d	d
 d
ZdS )z4ASR (Automatic Speech Recognition) namespace client.    )OptionalN   )OMITAsyncClientWrapperClientWrapperRequestOptions)ASRResponsec                   @   N   e Zd ZdZdefddZedddded	ee	 d
e
dee def
ddZdS )	ASRClientzSynchronous ASR operations.client_wrapperc                 C   
   || _ d S N_clientselfr    r   K/home/ubuntu/.local/lib/python3.10/site-packages/fishaudio/resources/asr.py__init__      
zASRClient.__init__TNlanguageinclude_timestampsrequest_optionsaudior   r   r   returnc                C   sJ   || d}|t ur||d< | jjddddit||d}t| S )a8  
        Transcribe audio to text.

        Args:
            audio: Audio file bytes
            language: Language code (e.g., "en", "zh"). Auto-detected if not provided.
            include_timestamps: Whether to include timestamp information for segments
            request_options: Request-level overrides

        Returns:
            ASRResponse with transcription text, duration, and segments

        Example:
            ```python
            client = FishAudio(api_key="...")

            with open("audio.mp3", "rb") as f:
                audio_bytes = f.read()

            result = client.asr.transcribe(audio=audio_bytes, language="en")
            print(result.text)
            for segment in result.segments:
                print(f"{segment.start}-{segment.end}: {segment.text}")
            ```
        r   ignore_timestampsr   POST/v1/asrContent-Typeapplication/msgpackheaderscontentr   r   r   request	ormsgpackpackbr   model_validatejsonr   r   r   r   r   payloadresponser   r   r   
transcribe   s   #	zASRClient.transcribe)__name__
__module____qualname____doc__r   r   r   bytesr   strboolr   r   r.   r   r   r   r   r
      "    r
   c                   @   r	   )AsyncASRClientzAsynchronous ASR operations.r   c                 C   r   r   r   r   r   r   r   r   L   r   zAsyncASRClient.__init__TNr   r   r   r   r   r   c                   sR   || d}|t ur||d< | jjddddit||dI dH }t| S )	a`  
        Transcribe audio to text (async).

        Args:
            audio: Audio file bytes
            language: Language code (e.g., "en", "zh"). Auto-detected if not provided.
            include_timestamps: Whether to include timestamp information for segments
            request_options: Request-level overrides

        Returns:
            ASRResponse with transcription text, duration, and segments

        Example:
            ```python
            client = AsyncFishAudio(api_key="...")

            async with aiofiles.open("audio.mp3", "rb") as f:
                audio_bytes = await f.read()

            result = await client.asr.transcribe(audio=audio_bytes, language="en")
            print(result.text)
            for segment in result.segments:
                print(f"{segment.start}-{segment.end}: {segment.text}")
            ```
        r   r   r   r   r    r!   r"   Nr%   r+   r   r   r   r.   O   s   #	zAsyncASRClient.transcribe)r/   r0   r1   r2   r   r   r   r3   r   r4   r5   r   r   r.   r   r   r   r   r7   I   r6   r7   )r2   typingr   r'   corer   r   r   r   typesr   r
   r7   r   r   r   r   <module>   s    >