a
    Sic~!                     @   sb   d Z ddlZddlZddlZddlmZ ddlm	Z	 ddlm
Z
 e
jZdZddd	Zdd
dZdS )a   Audio summaries and TensorFlow operations to create them.

An audio summary stores a rank-2 string tensor of shape `[k, 2]`, where
`k` is the number of audio clips recorded in the summary. Each row of
the tensor is a pair `[encoded_audio, label]`, where `encoded_audio` is
a binary string whose encoding is specified in the summary metadata, and
`label` is a UTF-8 encoded Markdown string describing the audio clip.

NOTE: This module is in beta, and its API is subject to change, but the
data that it stores to disk will be supported forever.
    Nencoder)metadata)
summary_v2zzLabels on audio summaries are deprecated and will be removed. See <https://github.com/tensorflow/tensorboard/issues/3513>.   c	              	   C   sr  |durt t ddlm  m}	 |du r0| }|du r<d}|dkrdtjd}t	j
|	jj|d}
ntd| |	|  |	|	|dg |d| }|	j|
||	jdd	}|du r|	d
g|	j|ddd }n|d| }|	j|	||gd}tj|||d}|	jjd|||dW  d   W  d   S 1 sD0    Y  W d   n1 sd0    Y  dS )ai  Create a legacy audio summary op for use in a TensorFlow graph.

    Arguments:
      name: A unique name for the generated summary node.
      audio: A `Tensor` representing audio data with shape `[k, t, c]`,
        where `k` is the number of audio clips, `t` is the number of
        frames, and `c` is the number of channels. Elements should be
        floating-point values in `[-1.0, 1.0]`. Any of the dimensions may
        be statically unknown (i.e., `None`).
      sample_rate: An `int` or rank-0 `int32` `Tensor` that represents the
        sample rate, in Hz. Must be positive.
      labels: Deprecated. Do not set.
      max_outputs: Optional `int` or rank-0 integer `Tensor`. At most this
        many audio clips will be emitted at each step. When more than
        `max_outputs` many clips are provided, the first `max_outputs`
        many clips will be used and the rest silently discarded.
      encoding: A constant `str` (not string tensor) indicating the
        desired encoding. You can choose any format you like, as long as
        it's "wav". Please see the "API compatibility note" below.
      display_name: Optional name for this summary in TensorBoard, as a
        constant `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.
      collections: Optional list of graph collections keys. The new
        summary op is added to these collections. Defaults to
        `[Graph Keys.SUMMARIES]`.

    Returns:
      A TensorFlow summary op.

    API compatibility note: The default value of the `encoding`
    argument is _not_ guaranteed to remain unchanged across TensorBoard
    versions. In the future, we will by default encode as FLAC instead of
    as WAV. If the specific format is important to you, please provide a
    file format explicitly.
    Nr   wavWAV)sample_rateUnknown encoding: %rr   Zencode_each_audio)dtypename )input   )adisplay_namedescriptionencodingaudio_summary)r   tensorcollectionssummary_metadata)warningswarn_LABELS_WARNINGtensorflow.compat.v1compatv1r   EncodingValue	functoolspartialaudio
encode_wav
ValueError
name_scopecontrol_dependenciesassert_rankmap_fnstringtileshape	transposestackcreate_summary_metadatasummarytensor_summary)r   r#   r	   labelsmax_outputsr   r   r   r   tfr   limited_audioencoded_audiolimited_labelsr   r    r8   ]/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorboard/plugins/audio/summary.pyop0   sF    /

 r:   c                    sH  |durt t ddlm  m t|}|jdkrHt	d|j
f |du rTd}|dkrztjd}tjtj|d nt	d| |d| }|du rd	gt| }	nfd
d|d| D }	 fdd|D }
t|
|	g }j|jd}|du r| }tj|||d}j| } }|jjd|  ||d |S )a  Create a legacy audio summary protobuf.

    This behaves as if you were to create an `op` with the same arguments
    (wrapped with constant tensors where appropriate) and then execute
    that summary op in a TensorFlow session.

    Arguments:
      name: A unique name for the generated summary node.
      audio: An `np.array` representing audio data with shape `[k, t, c]`,
        where `k` is the number of audio clips, `t` is the number of
        frames, and `c` is the number of channels. Elements should be
        floating-point values in `[-1.0, 1.0]`.
      sample_rate: An `int` that represents the sample rate, in Hz.
        Must be positive.
      labels: Deprecated. Do not set.
      max_outputs: Optional `int`. At most this many audio clips will be
        emitted. When more than `max_outputs` many clips are provided, the
        first `max_outputs` many clips will be used and the rest silently
        discarded.
      encoding: A constant `str` indicating the desired encoding. You
        can choose any format you like, as long as it's "wav". Please see
        the "API compatibility note" below.
      display_name: Optional name for this summary in TensorBoard, as a
        `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        `str`. Markdown is supported. Defaults to empty.

    Returns:
      A `tf.Summary` protobuf object.

    API compatibility note: The default value of the `encoding`
    argument is _not_ guaranteed to remain unchanged across TensorBoard
    versions. In the future, we will by default encode as FLAC instead of
    as WAV. If the specific format is important to you, please provide a
    file format explicitly.
    Nr   r   zShape %r must have rank 3r   r   )Zsamples_per_secondr
       c                    s   g | ]} j |qS r8   )r   as_bytes).0label)r4   r8   r9   
<listcomp>   s   zpb.<locals>.<listcomp>c                    s   g | ]} |qS r8   r8   )r=   r   r   r8   r9   r?      r;   )r   r   z%s/audio_summary)tagr   r   )r   r   r   r   r   r   nparrayndimr%   r,   r   r   r    r!   r"   encoder_utilr$   lenr-   make_tensor_protor*   r/   SummaryMetadata
FromStringSerializeToStringSummaryvalueadd)r   r#   r	   r2   r3   r   r   r   r5   r7   r6   contentr   r   Ztf_summary_metadatar0   r8   )r   r4   r9   pb   sL    .





rN   )Nr   NNNN)Nr   NNN)__doc__r!   r   numpyrA   Ztensorboard.utilr   rD   tensorboard.plugins.audior   r   r#   r   r:   rN   r8   r8   r8   r9   <module>   s,   
      
_     