
    yjy                        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          Z	d"d
Z
	 	 	 	 d#d$dZ	 	 	 d%d&d!ZdS )'    )annotations)TYPE_CHECKINGBinaryIO)Path)Tensorc                  N    e Zd ZU dZded<   ded<   ded<   ded<   de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                L    || _         || _        || _        || _        || _        d S )N)r   r   r   r   r   )selfr   r   r   r   r   s         m/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/audio/backends/backend.py__init__zAudioInfo.__init__"   s/     '&(.     N)r   r
   r   r
   r   r
   r   r
   r   r   r   r   )__name__
__module____qualname____doc____annotations__r    r   r   r	   r	      si         ::MMM! ! ! ! ! !r   r	   filepathstr | BinaryIOr   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   s    r   infor$   1   s    8 8
9
99r   T
str | Pathframe_offsetr
   
num_frames	normalizeboolchannels_firsttuple[Tensor, int]c                     t          d          )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+   s        r   loadr.   P   s    R 8
9
99r   N   r   srcr   r   r   
str | Noner   
int | Noner   c                     t          d          )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   r0   r   r+   r   r   s         r   saver4   |   s    P 8
9
99r   )r   r   r   r	   )r   r%   TT)r   r&   r'   r
   r(   r
   r)   r*   r+   r*   r   r,   )TNr/   )r   r   r0   r   r   r
   r+   r*   r   r1   r   r2   r   r   )
__future__r   typingr   r   pathlibr   paddler   r	   r$   r.   r4   r   r   r   <module>r9      s    # " " " " " * * * * * * * * ! ! ! ! ! ! ! !0: : : :B ): ): ): ): ):`  "$(: (: (: (: (: (: (:r   