Ë
    úmxiì0  ã                  ó‚  — 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       ú]/home/htdocs/ttos/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ˆÜ" <Ó0°AÒ5‘t¸<È¹?ˆØÐ#¬J°|Ä[Ô,QÜ(¨×):Ñ):¸V¸HÔ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  € ô �S‹kˆäØ�G‰GØØØØ õ	
ô 	# 5Ð*:Ô;ä4ØØà!%Ø�w‰wØØØØ#ô

ˆ
ô ,Ó-ÐØ)ÐÔØ"'ÐÔÜ$3°D·G±GÓ$<ÐÔ!Ø%-ÐÔ"Ü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@   