L i{0UddlmZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZmZddlmZmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZ dd l!m"Z#ddl!m$Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2er ddl3m4Z4ddlm5Z5e2e1zdzZ6de7d<hdZ8eGddZ9GddZ:y)) annotations) dataclass)dedent) TYPE_CHECKING TypeAliascast)enforce_filename_restriction)current_form_id) LayoutConfigvalidate_width)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)_get_upload_files)StreamlitAPIException) AudioInput)FileUploaderState)UploadedFileInfo)gather_metrics)ScriptRunContextget_script_run_ctx) WidgetArgsWidgetCallback WidgetKwargsregister_widget) DeletedFile UploadedFile)DeltaGenerator)WidthWithoutContentNrSomeUploadedAudioFile>}+"V@D逻]>c,eZdZ ddZ ddZy)AudioInputSerdec&t}|t|tr|S|jj }|j |_|j |_|j|_|jj|j|S)N) FileUploaderStateProto isinstancer uploaded_file_infoaddfile_idnamesize file_urlsCopyFrom _file_urls)self audio_file state_proto file_infos l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/widgets/audio_input.py serializezAudioInputSerde.serialize>sy-.  J !D +6+I+I+M+M+O &.. # # $$Z%:%:;ct|}t|dk(rdn|d}|'t|tst |j dg|S)Nrz.wav)rlenr1r r r5)r:ui_value upload_files return_values r> deserializezAudioInputSerde.deserializeOsL)2 "<0A5t<?  #J|[,Q ():):VH Er@N)r;r$returnr0)rCzFileUploaderStateProto | NonerGr$)__name__ __module__ __qualname__r?rFr@r>r.r.<s.) "5 r@r.c eZdZeddddddddddd d dZ d ddddd  dd Zedd Zy)AudioInputMixin audio_inputr,NFvisiblestretch) sample_ratekeyhelp on_changeargskwargsdisabledlabel_visibilitywidthc |'|tvrtd|dttdt} |j ||||||||| | |  S)aDisplay 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 Hz, which is optimal for speech recognition. The following sample rates are supported: 8000, 11025, 16000, 22050, 24000, 32000, 44100, or 48000. 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 zInvalid sample_rate: z. Must be one of z! Hz, or None for browser default.) labelrQrRrSrTrUrVrWrXrYctx)ALLOWED_SAMPLE_RATESrsortedr _audio_input) r:r[rQrRrSrTrUrVrWrXrYr\s r>rNzAudioInputMixin.audio_inputZs^  "{:N'N'' }5""()=">!??`b  !"  #-!  r@)rWrXrYr\c t|}t|j||ddt|| t d|d|j||| |} t } | | _|| _t|j| _ || _ t| | j_ ||| _|r|t|| _t#| t%| }t'}t)| j ||||j*|j,| d}|jj/d| | t1|jt2ry|jS) NF) default_valuewrites_allowedrNT)user_keykey_as_main_identitydgr[rSrYrQ)rYfile_uploader_state_value)on_change_handlerrUrV deserializer serializerr\ value_type) layout_config)rr rerrAudioInputProtoidr[r form_idrWrrXvaluerQrrSr r r.rrFr?_enqueuer1r )r:r[rQrRrSrTrUrVrWrXrYr\ element_idaudio_input_protorkserdeaudio_input_states r>r_zAudioInputMixin._audio_inputsYSk GG     #5*:;4 !%ww#  ,-)"'$3DGG$<!%-"3S 4 **0  ",7  ) T%%+D\  "u$51 !+  '**2   (9W '--{ ; &&&r@ctd|S)zGet our DeltaGenerator.r")r)r:s r>rezAudioInputMixin.dgJs$d++r@)r[strrQ int | NonerR Key | NonerS str | NonerTWidgetCallback | NonerUWidgetArgs | NonerVWidgetKwargs | NonerWboolrXrrYr#rGUploadedFile | None)r,NNNNN)r[rvrQrwrRrxrSryrTrzrUr{rVr|rWr}rXrrYr#r\zScriptRunContext | NonerGr~)rGr")rHrIrJrrNr_propertyrerKr@r>rMrMYsuM" #(+/"&&*,5%.a a  a  a  a )a  a $a a *a #a  a #a L#(+/"&&*J',5%.'+J'J' J' J'  J' ) J' J'$J'J'*J'#J'%J' J'X,,r@rM); __future__r dataclassesrtextwraprtypingrrr*streamlit.elements.lib.file_uploader_utilsr !streamlit.elements.lib.form_utilsr #streamlit.elements.lib.layout_utilsr r streamlit.elements.lib.policiesr rstreamlit.elements.lib.utilsrrrrr(streamlit.elements.widgets.file_uploaderrstreamlit.errorsrstreamlit.proto.AudioInput_pb2rrlstreamlit.proto.Common_pb2rr0rUploadedFileInfoProtostreamlit.runtime.metrics_utilrstreamlit.runtime.scriptrunnerrrstreamlit.runtime.staterrrr'streamlit.runtime.uploaded_file_managerr r!streamlit.delta_generatorr"r#r$__annotations__r]r.rMrKr@r>rs#!11S=LG2HRP9O N8G#/+#=#DyDO  8t,t,r@