o
    Me¦  ã                   @   s¾   d dl Z d dlmZ d dlmZmZmZ G dd„ dƒZdedefdd	„Z		 	
		ddeeef de
de
dededee je
f fdd„Z			ddede jde
dedee dee
 fdd„ZdS )é    N)ÚPath)ÚOptionalÚTupleÚUnionc                
   @   s.   e Zd ZdZdededededef
dd„Zd	S )
Ú	AudioInfoz2 Audio info, return type of backend info function Úsample_rateÚnum_samplesÚnum_channelsÚbits_per_sampleÚencodingc                 C   s"   || _ || _|| _|| _|| _d S )N)r   r   r	   r
   r   )Úselfr   r   r	   r
   r   © r   úMD:\Projects\ConvertPro\env\Lib\site-packages\paddle/audio/backends/backend.pyÚ__init__   s
   
zAudioInfo.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚstrr   r   r   r   r   r      s    ÿÿr   ÚfilepathÚreturnc                 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, 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   Úinfo!   s   r   éÿÿÿÿTÚframe_offsetÚ
num_framesÚ	normalizeÚchannels_firstc                 C   r   )ar  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)

    Exampels:
        .. 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, 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   Úload@   s   'r"   é   Úsrcr   r   r
   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 infomation
            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, 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   Úsavej   s   (r%   )r   r   TT)TNr#   )ZpaddleÚpathlibr   Útypingr   r   r   r   r   r   r   ÚboolZTensorr"   r%   r   r   r   r   Ú<module>   sH    üÿþýü
ü.úÿþýüûú