
    1VhN                     D    d Z ddlZddlmZ ddlmZ ddlmZ 	 	 	 	 ddZ	y)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_creatorc                 &   t        t        dd      ddlm |d}|dk7  rt	        d|z        t        j                  d|t
        j                  j                  d            }|g}t        t        j                  j                  d	d      xs t        j                  j                  }	 |	| d
|      5 \  }
}t        j                  fd       }t        j                  j                  |
|||      cddd       S # 1 sw Y   yxY w)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                  :   t         j                  j                  d       t         j                  j                         d  } t	        j
                  j                        }t        j                  || t         j                  d      t        j                  t        j                        d   dkD  fdd       t        j                  d	gt        j                  |       d d
       }t        j                  t        j                  |g            S )N   )sample_rateencode_each_audio)dtypename)inputr   c                       S N )encoded_audios   T/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/audio/summary_v2.py<lambda>z,audio.<locals>.lazy_tensor.<locals>.<lambda>s   s         c                  J    t        j                  g t         j                        S r   )tfconstantstringr   r   r   r   z,audio.<locals>.lazy_tensor.<locals>.<lambda>t   s    B		2 r       )a)r    	debuggingassert_rankassert_non_negative	functoolspartial
encode_wavmap_fnr"   condshapetile	transposestack)limited_audio	encode_fnlimited_labelsr   	audio_opsdatamax_outputsr   s      @r   lazy_tensorzaudio.<locals>.lazy_tensorb   s    LL$$T1-LL,,[9 +.M!))$$+I IIii(	M GG}-a014%2M
  WWbT288-+H!+LMN<<"((M>+J"KLLr   )tagtensorstepr   )getattrr    tensorflow.python.opsr   
ValueErrorr   create_summary_metadataEncodingValuesummaryexperimentalr   r   LazyTensorCreatorwrite)r   r6   r   r;   r7   r   r   summary_metadatainputsr   r9   _r8   r5   s    `` `        @r   r   r       s   T GT*ID5/(:;;77""((/
 Kd3F 	

''$? 	$::##  
t_V	< 
a 
	.	.	M 
/	M0 zzKd=M   
;
 
 
s   <ADD)Nr   NN)
__doc__r)   tensorboard.compatr   r    tensorboard.plugins.audior   tensorboard.utilr   r   r   r   r   <module>rM      s,     ( . 0 
]
r   