o
    ðpiy  ã                   @  sz   d dl mZ d dlmZmZ erd dlmZ d dlmZ G dd„ dƒZ	d%d
d„Z
	 			d&d'dd„Z			d(d)d#d$„ZdS )*é    )Úannotations)ÚTYPE_CHECKINGÚBinaryIO)ÚPath)ÚTensorc                   @  sD   e Zd ZU dZded< ded< ded< ded< ded< ddd„ZdS )Ú	AudioInfoz0Audio info, return type of backend info functionÚintÚsample_rateÚnum_samplesÚnum_channelsÚbits_per_sampleÚstrÚencodingÚreturnÚNonec                 C  s"   || _ || _|| _|| _|| _d S )N)r	   r
   r   r   r   )Úselfr	   r
   r   r   r   © r   úd/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddle/audio/backends/backend.pyÚ__init__"   s
   
zAudioInfo.__init__N)r	   r   r
   r   r   r   r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r   r   r      s   
 r   Úfilepathústr | BinaryIOr   c                 C  ó   t dƒ‚)a  Get signal information of input audio file.

    Args:
        filepath: audio path or file object.

    Returns:
        AudioInfo: info of the given audio.

    Example:
        .. code-block:: python

            >>> import os
            >>> import paddle

            >>> sample_rate = 16000
            >>> wav_duration = 0.5
            >>> num_channels = 1
            >>> num_frames = sample_rate * wav_duration
            >>> wav_data = paddle.linspace(-1.0, 1.0, int(num_frames)) * 0.1
            >>> waveform = wav_data.tile([num_channels, 1])
            >>> base_dir = os.getcwd()
            >>> filepath = os.path.join(base_dir, "test.wav")

            >>> paddle.audio.save(filepath, waveform, sample_rate)
            >>> wav_info = paddle.audio.info(filepath)
    úplease set audio backend©ÚNotImplementedError)r   r   r   r   Úinfo1   s   r    éÿÿÿÿTú
str | PathÚframe_offsetr   Ú
num_framesÚ	normalizeÚboolÚchannels_firstútuple[Tensor, int]c                 C  r   )a§  Load audio data from file.Load the audio content start form frame_offset, and get num_frames.

    Args:
        frame_offset: from 0 to total frames,
        num_frames: from -1 (means total frames) or number frames which want to read,
        normalize:
            if True: return audio which norm to (-1, 1), dtype=float32
            if False: return audio with raw data, dtype=int16

        channels_first:
            if True: return audio with shape (channels, time)

    Return:
        Tuple[paddle.Tensor, int]: (audio_content, sample rate)

    Examples:
        .. code-block:: python

            >>> import os
            >>> import paddle

            >>> sample_rate = 16000
            >>> wav_duration = 0.5
            >>> num_channels = 1
            >>> num_frames = sample_rate * wav_duration
            >>> wav_data = paddle.linspace(-1.0, 1.0, int(num_frames)) * 0.1
            >>> waveform = wav_data.tile([num_channels, 1])
            >>> base_dir = os.getcwd()
            >>> filepath = os.path.join(base_dir, "test.wav")

            >>> paddle.audio.save(filepath, waveform, sample_rate)
            >>> wav_data_read, sr = paddle.audio.load(filepath)
    r   r   )r   r#   r$   r%   r'   r   r   r   ÚloadP   s   )r)   Né   r   Úsrcr   r	   r   ú
str | Noner   ú
int | Noner   c                 C  r   )aé  
    Save audio tensor to file.

    Args:
        filepath: saved path
        src: the audio tensor
        sample_rate: the number of samples of audio per second.
        channels_first: src channel information
            if True, means input tensor is (channels, time)
            if False, means input tensor is (time, channels)
        encoding:encoding format, wave_backend only support PCM16 now.
        bits_per_sample: bits per sample, wave_backend only support 16 bits now.

    Returns:
        None

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> sample_rate = 16000
            >>> wav_duration = 0.5
            >>> num_channels = 1
            >>> num_frames = sample_rate * wav_duration
            >>> wav_data = paddle.linspace(-1.0, 1.0, int(num_frames)) * 0.1
            >>> waveform = wav_data.tile([num_channels, 1])
            >>> filepath = "./test.wav"

            >>> paddle.audio.save(filepath, waveform, sample_rate)
    r   r   )r   r+   r	   r'   r   r   r   r   r   Úsave|   s   (r.   )r   r   r   r   )r   r!   TT)r   r"   r#   r   r$   r   r%   r&   r'   r&   r   r(   )TNr*   )r   r   r+   r   r	   r   r'   r&   r   r,   r   r-   r   r   )Ú
__future__r   Útypingr   r   Úpathlibr   Zpaddler   r   r    r)   r.   r   r   r   r   Ú<module>   s    
!û0ú