o
    „ôjë  ã                   @   sL   d Z ddlZddlmZ G dd„ dejƒZeƒ ZG dd„ dejƒZeƒ Z	dS )zCTensorBoard encoder helper module.

Encoder depends on TensorFlow.
é    N)Úop_evaluatorc                       ó0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )Ú_TensorFlowPngEncoderab  Encode an image to PNG.

    This function is thread-safe, and has high performance when run in
    parallel. See `encode_png_benchmark.py` for details.

    Arguments:
      image: A numpy array of shape `[height, width, channels]`, where
        `channels` is 1, 3, or 4, and of dtype uint8.

    Returns:
      A bytestring with PNG-encoded data.
    c                    s   t ƒ  ¡  d | _d | _d S ©N)ÚsuperÚ__init__Ú_image_placeholderÚ
_encode_op©Úself©Ú	__class__© úi/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/tensorboard/util/encoder.pyr   (   s   

z_TensorFlowPngEncoder.__init__c                 C   s8   dd l m  m} |j|jdd�| _|j | j¡| _d S )Nr   Úimage_to_encode©ÚdtypeÚname)	Útensorflow.compat.v1ÚcompatÚv1ÚplaceholderÚuint8r   ÚimageÚ
encode_pngr	   ©r   Útfr   r   r   Úinitialize_graph-   s
   ÿz&_TensorFlowPngEncoder.initialize_graphc                 C   sF   t |tjƒstd| ƒ‚|jtjkrtd|j ƒ‚| jj| j|id�S )Nz!'image' must be a numpy array: %rz&'image' dtype must be uint8, but is %r©Ú	feed_dict)	Ú
isinstanceÚnpÚndarrayÚ
ValueErrorr   r   r	   Úevalr   )r   r   r   r   r   Úrun6   s   ÿz_TensorFlowPngEncoder.run©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   Ú__classcell__r   r   r   r   r      s
    	r   c                       r   )Ú_TensorFlowWavEncodera!  Encode an audio clip to WAV.

    This function is thread-safe and exhibits good parallel performance.

    Arguments:
      audio: A numpy array of shape `[samples, channels]`.
      samples_per_second: A positive `int`, in Hz.

    Returns:
      A bytestring with WAV-encoded data.
    c                    s    t ƒ  ¡  d | _d | _d | _d S r   )r   r   Ú_audio_placeholderÚ_samples_per_second_placeholderr	   r
   r   r   r   r   P   s   

z_TensorFlowWavEncoder.__init__c                 C   sP   dd l m  m} |j|jdd�| _|j|jdd�| _|jj	| j| jd�| _
d S )Nr   r   r   Úsamples_per_second)Úsample_rate)r   r   r   r   Úfloat32r-   Úint32r.   ÚaudioÚ
encode_wavr	   r   r   r   r   r   V   s   ÿÿþz&_TensorFlowWavEncoder.initialize_graphc                 C   sL   t |tjƒstd| ƒ‚t |tƒstd| ƒ‚| j|| j|i}| jj|d�S )Nz!'audio' must be a numpy array: %rz''samples_per_second' must be an int: %rr   )	r    r!   r"   r#   Úintr-   r.   r	   r$   )r   r3   r/   r   r   r   r   r%   e   s   
ÿþz_TensorFlowWavEncoder.runr&   r   r   r   r   r,   C   s
    r,   )
r*   Únumpyr!   Útensorboard.utilr   ZPersistentOpEvaluatorr   r   r,   r4   r   r   r   r   Ú<module>   s   &
2