【问题标题】:How do you record user's audio in Streamlit shearing?您如何在 Streamlit 剪切中录制用户的音频?
【发布时间】:2021-07-23 00:14:09
【问题描述】:

我希望部署一个小型数据收集应用程序,允许用户记录自己说的一些短语。

用 streamlit 构建它。

我可以让它在本地工作,但似乎找不到适用于 Streamlit-Shearing 服务的解决方案。

有什么想法吗?

【问题讨论】:

    标签: python streamlit


    【解决方案1】:

    我不完全理解你的问题,我认为这可能会有所帮助。

    import streamlit as st
    from bokeh.models.widgets import Button
    from bokeh.models import CustomJS
    from streamlit_bokeh_events import streamlit_bokeh_events
    
    stt_button = Button(label="Speak", width=100)
    
    stt_button.js_on_event("button_click", CustomJS(code="""
    var recognition = new webkitSpeechRecognition();
    recognition.continuous = true;
    recognition.interimResults = true;
    
    recognition.onresult = function (e) {
        var value = "";
        for (var i = e.resultIndex; i < e.results.length; ++i) {
            if (e.results[i].isFinal) {
                value += e.results[i][0].transcript;
            }
        }
        if ( value != "") {
            document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value}));
        }
    }
    recognition.start();
    """))
    
    result = streamlit_bokeh_events(
    stt_button,
    events="GET_TEXT",
    key="listen",
    refresh_on_update=False,
    override_height=75,
    debounce_time=0)
    
    if result:
    if "GET_TEXT" in result:
        st.write(result.get("GET_TEXT"))`
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2014-10-30
      • 1970-01-01
      • 2012-06-14
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多