o
    Ni                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
  mZ ddlmZ dZdZd	Zd
ZdZddefddZddefddZddefddZeefddZdeefddZdeefddZdS )z/Utility library to generate dataset-like files.    )absolute_import)division)print_functionN)utils
         iD     c                 C   s:   | pt tt} |pt tt}tj jd| ||ftjdS )z+Returns random picture as np.ndarray (int).   )sizedtype)random	randrangeMIN_HEIGHT_WIDTHMAX_HEIGHT_WIDTHnprandintuint8)heightwidthchannels r   _/home/ubuntu/.local/lib/python3.10/site-packages/tensorflow_datasets/testing/fake_data_utils.pyget_random_picture'   s
   r   c                 C   sr   t | ||}tj|}t }||}W d   n1 s w   Y  tjdddd}|	| |
  |jS )zReturns path to JPEG picture.NFwbz.JPEGdeletemodesuffix)r   tfimageencode_jpegr   nogpu_sessionruntempfileNamedTemporaryFilewriteclosename)r   r   r   r    jpegsessresfobjr   r   r   get_random_jpeg/   s   

r-   c                 C   s   t dd|}| dur|durtjt|d| |fd }tj|}t }||}W d   n1 s7w   Y  t	j
dddd}|| |  |jS )zReturns path to PNG picture.   Nr   Fr   z.PNGr   )r   r   r    resize_nearest_neighborexpand_dims
encode_pngr   r"   r#   r$   r%   r&   r'   r(   )r   r   r   r    pngr*   r+   r,   r   r   r   get_random_png;   s   

r3   c                 C   s>   t | | }t dt j | d | t j}|d }|S )z-Returns random audio as np.ndarray (float32).   g     {@g333333?)r   arangesinpiastypefloat32)durationsamplesample_numberwaveformr   r   r   get_random_audioL   s   r>      c                 C      t ||d| }tj||}t }||}W d   n1 s$w   Y  tj	dddd}|
| W d   |jS 1 sCw   Y  |jS )z.Returns path to WAV audio having channels = 1.NFr   .wavr   r>   reshaper   audio
encode_wavr   r"   r#   r$   r%   r&   r(   r   r:   r;   rE   wavr*   r+   fr   r   r   get_random_wav_c1U      

rJ   r4   c                 C   r@   )z.Returns path to WAV audio having channels = 2.rA   NFr   rB   r   rC   rG   r   r   r   get_random_wav_c2a   rK   rL   )__doc__
__future__r   r   r   r   r$   numpyr   tensorflow.compat.v1compatv1r   tensorflow_datasets.corer   r   r   CHANNELS_NB_SAMPLE_RATE_AUDIO_DURATIONr   r-   r3   r>   rJ   rL   r   r   r   r   <module>   s,   

