
    ͑i                        S SK Jr  S SKrS SKJrJr  S SKrS SKrSSK	J
r
  \(       a  S SKJr  S SKJr  S rSS	 jr    S           SS
 jjr   S             SS jjrg)    )annotationsN)TYPE_CHECKINGBinaryIO   )	AudioInfo)Path)Tensorc                     Sn SU  S3nU$ )Npaddleaudiozxonly PCM16 WAV supported. 
if want support more other audio types, please manually installed (usually with `pip install zQ`). 
 and use paddle.audio.backends.set_backend('soundfile') to set audio backend )packagewarn_msgs     b/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/audio/backends/wave_backend.py_error_messager       s*    G	99@	 BV	V  O    c                   [        U S5      (       a  U nO[        U S5      n [        R                  " U5      nUR                  5       nUR                  5       nUR                  5       nUR                  5       S-  nSnUR                  5         [        XVXGU5      $ ! [        R                   a7    UR	                  S5        UR                  5         [        5       n[        U5      ef = f)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)
readrbr      PCM_S)hasattropenwaveErrorseekcloser   NotImplementedErrorgetnchannelsgetframerate
getnframesgetsampwidthr   )	filepathfile_objfile_err_msgchannelssample_ratesample_framesbits_per_sampleencodings	            r   infor+   +   s    8 x  $'+		(# !!#H$$&K$$&M((*Q.OHNNHx  :: +a "!'**	+s   B AC%c                   [        U S5      (       a  U nO[        U S5      n [        R                  " U5      nUR                  5       nUR                  5       n	UR                  5       n
UR                  U
5      nUR                  5         [        R                  " U[        R                  S9nUR                  [        R                   5      nU(       a  US-  nOUn[        R"                  " XU45      nUS:w  a  XX-   2SS24   n[$        R&                  " U5      nU(       a  [$        R(                  " USS/S	9nX4$ ! [        R                   a7    UR	                  S5        UR                  5         [        5       n[        U5      ef = f)
aD  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   )dtype   Nr   )perm)r   r   r   r   r   r   r   r   r   r   r    
readframesnp
frombufferint16astypefloat32reshapepaddle	to_tensor	transpose)r"   frame_offset
num_frames	normalizechannels_firstr#   r$   r%   r&   r'   framesaudio_contentaudio_as_np16audio_as_np32
audio_normwaveforms                   r   loadrE   _   sZ   P x  $'+		(# !!#H$$&KF$$V,MNN MM-rxx@M!((4M"e,
 #
zz*x&89HR<+DDaGH)H##HAq6:  ; :: +a "!'**	+s   D; ;AFc                R   UR                   S:X  d   S5       eUR                  5       nU(       a  [        R                  " U5      nUR                  S   nUS;  a  [        S5      e[        US-  5      nUR                  [        R                  :X  a  US-  R                  S5      n[        R                  " U S	5       n	U	R                  U5        U	R                  U5        U	R                  U5        U	R!                  UR#                  5       5        S
S
S
5        g
! , (       d  f       g
= f)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: audio 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)
   zExpected 2D tensorr   )N   z,Invalid bits_per_sample, only support 16 bitr   r.   z<hwN)ndimnumpyr2   r:   shape
ValueErrorintr-   r8   r6   r5   r   r   setnchannelssetsampwidthsetframeratewriteframestobytes)
r"   srcr'   r>   r*   r)   audio_numpyr&   sample_widthfs
             r   saverX      s    N 88q=...=))+K ll;/  #H j(GHH*+L
yyFNN""e,44T:	8S	!Q	x 	|$	{#	k))+,	 
"	!	!s   <AD
D&)r"   zstr | BinaryIOreturnr   )r   r/   TT)r"   z
str | Pathr;   rN   r<   rN   r=   boolr>   rZ   rY   ztuple[Tensor, int])TNrH   )r"   strrT   r	   r'   rN   r>   rZ   r*   z
str | Noner)   z
int | NonerY   None)
__future__r   r   typingr   r   rK   r2   r8   backendr   pathlibr   r	   r   r+   rE   rX   r   r   r   <module>ra      s    #  *   1l L!L!L! L! 	L!
 L! L!f  "$>->-	>- >- 	>-
 >-  >- 
>-r   