o
    2hN                     @   sF   d Z ddlZddlmZ ddlmZ ddlmZ 				d	ddZ	dS )
a  Audio summaries and TensorFlow operations to create them, V2 versions.

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.
    N)tf2)metadata)lazy_tensor_creator   c                    s   t tdd  du rddlm  |du rd}|dkr td| tjd|tjdd}|g}t tj	j
d	dp=tj	j}	|	| d
|d \}
}tj fdd}tj	j|
|||dW  d   S 1 shw   Y  dS )a  Write an audio summary.

    Arguments:
      name: A name for this summary. The summary tag used for TensorBoard will
        be this name prefixed by any active name scopes.
      data: 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.
      step: Explicit `int64`-castable monotonic step value for this summary. If
        omitted, this defaults to `tf.summary.experimental.get_step()`, which must
        not be None.
      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: Optional constant `str` for the desired encoding. Only "wav"
        is currently supported, but this is not guaranteed to remain the
        default, so if you want "wav" in particular, set this explicitly.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.

    Returns:
      True on success, or false if no summary was emitted because no default
      summary writer was available.

    Raises:
      ValueError: if a default writer exists, but no step was provided and
        `tf.summary.experimental.get_step()` is None.
    audioNr   )gen_audio_opswavzUnknown encoding: %rWAV)display_namedescriptionencodingsummary_scopeaudio_summary)valuesc                     s   t jd t j d  } tjjd}t j|| t jdd t 	t j
 dd dk fddd	d  t d
gt j
| dd d }t jt  |gdS )Nr   )sample_rateencode_each_audio)dtypename)inputr   c                      s    S N r   encoded_audior   _/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/plugins/audio/summary_v2.py<lambda>s   s    z,audio.<locals>.lazy_tensor.<locals>.<lambda>c                   S   s   t g t jS r   )tfconstantstringr   r   r   r   r   t   s        )a)r   	debuggingassert_rankassert_non_negative	functoolspartial
encode_wavmap_fnr   condshapetile	transposestack)limited_audio	encode_fnlimited_labels	audio_opsdatamax_outputsr   r   r   lazy_tensorb   s&   
zaudio.<locals>.lazy_tensor)tagtensorstepr   )getattrr   tensorflow.python.opsr   
ValueErrorr   create_summary_metadataEncodingValuesummaryexperimentalr   r   LazyTensorCreatorwrite)r   r2   r   r7   r3   r   r   summary_metadatainputsr   r5   _r4   r   r0   r   r       s.   *
$r   )Nr   NN)
__doc__r$   tensorboard.compatr   r   tensorboard.plugins.audior   tensorboard.utilr   r   r   r   r   r   <module>   s   
