o
    ,&]i0                     @  sj  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rd dl3m4Z4 d dlm5Z5 e2e1B dB Z6de7d< h dZ8eG dd dZ9G dd dZ:dS )    )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                   @  s    e Zd ZdddZdd	d
ZdS )AudioInputSerde
audio_filer#   returnFileUploaderStateProtoc                 C  sP   t  }|d u st|tr|S |j }|j|_|j|_|j|_|j	|j
 |S )N)r/   
isinstancer   uploaded_file_infoaddfile_idnamesize	file_urlsCopyFrom
_file_urls)selfr-   state_proto	file_info r<   d/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/elements/widgets/audio_input.py	serialize>   s   
zAudioInputSerde.serializeui_valueFileUploaderStateProto | Nonec                 C  sD   t |}t|dkrd n|d }|d ur t|ts t|jdg |S )Nr   z.wav)r   lenr0   r   r   r4   )r9   r?   upload_filesreturn_valuer<   r<   r=   deserializeO   s
   zAudioInputSerde.deserializeN)r-   r#   r.   r/   )r?   r@   r.   r#   )__name__
__module____qualname__r>   rD   r<   r<   r<   r=   r,   <   s    
r,   c                   @  sf   e Zd Zeddddddddddd	d(ddZ						d)ddddd d*d#d$Zed+d&d'ZdS ),AudioInputMixinaudio_inputr+   NFvisiblestretch)	sample_ratekeyhelp	on_changeargskwargsdisabledlabel_visibilitywidthlabelstrrL   
int | NonerM   
Key | NonerN   
str | NonerO   WidgetCallback | NonerP   WidgetArgs | NonerQ   WidgetKwargs | NonerR   boolrS   r   rT   r"   r.   UploadedFile | Nonec       	         C  sP   |dur|t vrtd| dtt  dt }| j|||||||||	|
|d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

        NzInvalid sample_rate: z. Must be one of z! Hz, or None for browser default.)rU   rL   rM   rN   rO   rP   rQ   rR   rS   rT   ctx)ALLOWED_SAMPLE_RATESr   sortedr   _audio_input)r9   rU   rL   rM   rN   rO   rP   rQ   rR   rS   rT   r_   r<   r<   r=   rI   Z   s*    zAudioInputMixin.audio_input)rR   rS   rT   r_   r_   ScriptRunContext | Nonec             
   C  s   t |}t| j||d dd t||	 td|d| j|||
|d}t }||_||_t| j|_	||_
t|	|j_|d ur?||_|rJ|d urJt||_t|
 t|
d}t }t|j||||j|j|dd}| jjd||d	 t|jtrvd S |jS )
NF)default_valuewrites_allowedrI   T)user_keykey_as_main_identitydgrU   rN   rT   rL   )rT   file_uploader_state_value)on_change_handlerrP   rQ   deserializer
serializerr_   
value_type)layout_config)r   r   rh   r   r   AudioInputProtoidrU   r	   form_idrR   r   rS   valuerL   r   rN   r   r
   r,   r   rD   r>   _enqueuer0   r   )r9   rU   rL   rM   rN   rO   rP   rQ   rR   rS   rT   r_   
element_idaudio_input_protorn   serdeaudio_input_stater<   r<   r=   rb      s`   


zAudioInputMixin._audio_inputr!   c                 C  s
   t d| S )zGet our DeltaGenerator.r!   )r   )r9   r<   r<   r=   rh   K  s   
zAudioInputMixin.dg)rU   rV   rL   rW   rM   rX   rN   rY   rO   rZ   rP   r[   rQ   r\   rR   r]   rS   r   rT   r"   r.   r^   )r+   NNNNN)rU   rV   rL   rW   rM   rX   rN   rY   rO   rZ   rP   r[   rQ   r\   rR   r]   rS   r   rT   r"   r_   rc   r.   r^   )r.   r!   )rE   rF   rG   r   rI   rb   propertyrh   r<   r<   r<   r=   rH   Y   s6     (
LrH   );
__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   ro   streamlit.proto.Common_pb2r   r/   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,   rH   r<   r<   r<   r=   <module>   s4   