o
    i!
                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlZd dlmZmZmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZ d dl m!Z!m"Z" 					dd ddZ#g dZ$dS )!    )annotations)	b64encode)BytesIO)Path)OptionalTupleUnionN)
AudioCacheclipfrom_ndarray	get_dtype
get_formatsplit_audio_frame
to_ndarray)Dtype)	AudioPipe)ReaderStreamReaderaformatinfo
load_audio)Writer
save_audioFTWAVaudioUnion[str, Path, np.ndarray]rateOptional[int]dtypeOptional[Dtype]to_monoboolmake_wavformatstrreturnTuple[str, int]c                 C  s   t | ttfrt| |||d\} }t| tj} |r9t }t|| ||d t	|
 d} d| d|  } | |fS t| } t	| d} | |fS )a  
    Transform an audio to a PCM bytestring.

    Args:
        audio: The file path to an audio file or a numpy array.
        rate: The sample rate of the audio.
        dtype: The data type of the audio.
        to_mono: Whether to convert the audio to mono.
        make_wav: Whether to make the audio a WAV file.
        format: The format of the audio container.
    Returns:
        The audio as a PCM bytestring and the sample rate of the audio.
    )r   r   r    )r#   asciizdata:audio/z;base64,)
isinstancer$   r   r   r
   npint16r   r   r   getvaluedecodeascontiguousarray)r   r   r   r    r"   r#   
bytestream r/   E/home/ubuntu/.local/lib/python3.10/site-packages/audiolab/__init__.pyencode'   s   
r1   )r	   r   r   r   r   r   r1   r   r   r   r   r   r   r   r   )NNFTr   )r   r   r   r   r   r   r    r!   r"   r!   r#   r$   r%   r&   )%
__future__r   base64r   ior   pathlibr   typingr   r   r   numpyr)   audiolab.avr	   r
   r   r   r   r   r   audiolab.av.typingr   audiolab.piper   audiolab.readerr   r   r   r   r   audiolab.writerr   r   r1   __all__r/   r/   r/   r0   <module>   s$   $	$