
    ȯei0                       U d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZmZmZmZmZ d d
lmZ d dlmZ d dlmZ  d dl!m"Z# d dl!m$Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 erd dl3m4Z4 d dlm5Z5 e2e1z  dz  Z6de7d<   h dZ8e G d d             Z9 G d d      Z:y)    )annotations)	dataclass)dedent)TYPE_CHECKING	TypeAliascast)enforce_filename_restriction)current_form_id)LayoutConfigvalidate_width)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)_get_upload_files)StreamlitAPIException)
AudioInput)FileUploaderState)UploadedFileInfo)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)DeletedFileUploadedFile)DeltaGenerator)WidthWithoutContentNr   SomeUploadedAudioFile>    }  +  "V  @  D  逻  ]  >  c                  ,    e Zd Z	 	 	 	 ddZ	 	 	 	 ddZy)AudioInputSerdec                &   t               }|t        |t              r|S |j                  j	                         }|j
                  |_        |j                  |_        |j                  |_        |j                  j                  |j                         |S )N)FileUploaderStateProto
isinstancer    uploaded_file_infoaddfile_idnamesize	file_urlsCopyFrom
_file_urls)self
audio_filestate_proto	file_infos       h/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/elements/widgets/audio_input.py	serializezAudioInputSerde.serialize>   sy     -.J!D+6+I+I+M+M+O	&..	#	#	$$Z%:%:;    c                    t        |      }t        |      dk(  rd n|d   }|'t        |t              st	        |j
                  dg       |S )Nr   z.wav)r   lenr1   r    r	   r5   )r:   ui_valueupload_filesreturn_values       r>   deserializezAudioInputSerde.deserializeO   sL     )2"<0A5t<?#J|[,Q():):VHEr@   N)r;   r$   returnr0   )rC   zFileUploaderStateProto | NonerG   r$   )__name__
__module____qualname__r?   rF    r@   r>   r.   r.   <   s.    ) 
 "5	r@   r.   c                      e Zd Z ed      dddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 dddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Zedd       Zy)AudioInputMixinaudio_inputr,   NFvisiblestretch)	sample_ratekeyhelp	on_changeargskwargsdisabledlabel_visibilitywidthc       	            |'|t         vrt        d| dt        t                d      t               }| j	                  |||||||||	|
|      S )a'  Display a widget that returns an audio recording from the user's microphone.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this widget is used for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        sample_rate : int or None
            The target sample rate for the audio recording in Hz. This
            defaults to ``16000``, which is optimal for speech recognition.

            The following values are supported: ``8000`` (telephone quality),
            ``11025``, ``16000`` (speech-recognition quality), ``22050``,
            ``24000``, ``32000``, ``44100``, ``48000`` (high-quality), or
            ``None``. If this is ``None``, the widget uses the browser's
            default sample rate (typically 44100 or 48000 Hz).

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this audio input's value
            changes.

        args : list or tuple
            An optional list or tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        disabled : bool
            An optional boolean that disables the audio input if set to
            ``True``. Default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget aligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        width : "stretch" or int
            The width of the audio input widget. This can be one of the following:

            - ``"stretch"`` (default): The width of the widget matches the
              width of the parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        Returns
        -------
        None or UploadedFile
            The ``UploadedFile`` class is a subclass of ``BytesIO``, and
            therefore is "file-like". This means you can pass an instance of it
            anywhere a file is expected. The MIME type for the audio data is
            ``audio/wav``.

            .. Note::
                The resulting ``UploadedFile`` is subject to the size
                limitation configured in ``server.maxUploadSize``. If you
                expect large sound files, update the configuration option
                appropriately.

        Examples
        --------
        *Example 1:* Record a voice message and play it back.*

        The default sample rate of 16000 Hz is optimal for speech recognition.

        >>> import streamlit as st
        >>>
        >>> audio_value = st.audio_input("Record a voice message")
        >>>
        >>> if audio_value:
        ...     st.audio(audio_value)

        .. output::
           https://doc-audio-input.streamlit.app/
           height: 260px

        *Example 2:* Record high-fidelity audio and play it back.*

        Higher sample rates can create higher-quality, larger audio files. This
        might require a nicer microphone to fully appreciate the difference.

        >>> import streamlit as st
        >>>
        >>> audio_value = st.audio_input("Record high quality audio", sample_rate=48000)
        >>>
        >>> if audio_value:
        ...     st.audio(audio_value)

        .. output::
           https://doc-audio-input-high-rate.streamlit.app/
           height: 260px

        zInvalid sample_rate: z. Must be one of z! Hz, or None for browser default.)labelrQ   rR   rS   rT   rU   rV   rW   rX   rY   ctx)ALLOWED_SAMPLE_RATESr   sortedr   _audio_input)r:   r[   rQ   rR   rS   rT   rU   rV   rW   rX   rY   r\   s               r>   rN   zAudioInputMixin.audio_inputZ   s    ` "{:N'N''} 5""()=">!??`b 
 !"  #- ! 
 	
r@   )rW   rX   rY   r\   c          
        t        |      }t        | j                  ||d d       t        ||	       t	        d|d| j                  |||
|      }t               }||_        ||_        t        | j                        |_	        ||_
        t        |	      |j                  _        |||_        |r|t        |      |_        t#        |
       t%        |
      }t'               }t)        |j                  ||||j*                  |j,                  |d      }| j                  j/                  d||	       t1        |j                  t2              ry |j                  S )
NF)default_valuewrites_allowedrN   T)user_keykey_as_main_identitydgr[   rS   rY   rQ   )rY   file_uploader_state_value)on_change_handlerrU   rV   deserializer
serializerr\   
value_type)layout_config)r   r   re   r   r   AudioInputProtoidr[   r
   form_idrW   r   rX   valuerQ   r   rS   r   r   r.   r   rF   r?   _enqueuer1   r    )r:   r[   rQ   rR   rS   rT   rU   rV   rW   rX   rY   r\   
element_idaudio_input_protork   serdeaudio_input_states                    r>   r_   zAudioInputMixin._audio_input   sY    SkGG 	
 	#5*:;4!%ww#


 ,-)"'$3DGG$<!%-"3S4
**0
 ",7)T%%+D\"u$51!+  '**2	
 	(9W'--{; &&&r@   c                    t        d|       S )zGet our DeltaGenerator.r"   )r   )r:   s    r>   re   zAudioInputMixin.dgK  s     $d++r@   )r[   strrQ   
int | NonerR   
Key | NonerS   
str | NonerT   WidgetCallback | NonerU   WidgetArgs | NonerV   WidgetKwargs | NonerW   boolrX   r   rY   r#   rG   UploadedFile | None)r,   NNNNN)r[   rv   rQ   rw   rR   rx   rS   ry   rT   rz   rU   r{   rV   r|   rW   r}   rX   r   rY   r#   r\   zScriptRunContext | NonerG   r~   )rG   r"   )rH   rI   rJ   r   rN   r_   propertyre   rK   r@   r>   rM   rM   Y   su   M"
 #(+/"&&*,5%.b
b
  	b

 b
 b
 )b
  b
 $b
 b
 *b
 #b
 
b
 #b
N #(+/"&&*J' ,5%.'+J'J'  J' 	J'
 J' )J'  J' $J' J' *J' #J' %J' 
J'X , ,r@   rM   );
__future__r   dataclassesr   textwrapr   typingr   r   r   *streamlit.elements.lib.file_uploader_utilsr	   !streamlit.elements.lib.form_utilsr
   #streamlit.elements.lib.layout_utilsr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   (streamlit.elements.widgets.file_uploaderr   streamlit.errorsr   streamlit.proto.AudioInput_pb2r   rl   streamlit.proto.Common_pb2r   r0   r   UploadedFileInfoProtostreamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   'streamlit.runtime.uploaded_file_managerr    r!   streamlit.delta_generatorr"   r#   r$   __annotations__r]   r.   rM   rK   r@   r>   <module>r      s    # !  1 1 S = L  G 2 H R P 9 O  N8G#/+#=#D y D O    8u, u,r@   