File size: 1,104 Bytes
be921cd
e3162fd
be921cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import streamlit.components.v1 as components

# Declare the component with a path to index.html
mycomponent = components.declare_component(
    "mycomponent",
    path=os.path.dirname(os.path.abspath(__file__))
)

# Python function to interact with the component
def speech_component(default_value=""):
    """
    A custom Streamlit component for continuous speech recognition.
    
    Args:
        default_value (str): Initial value to display in the input field.
    
    Returns:
        dict: The latest transcript data from the component.
    """
    # Pass the default value to the component and receive data back
    component_value = mycomponent(my_input_value=default_value, key="speech_component")
    
    # If no value is returned yet, return an empty dict
    if component_value is None:
        return {"value": ""}
    
    # Return the component value (expecting a dict with 'value' key)
    return component_value

if __name__ == "__main__":
    # Test the component standalone
    value = speech_component("Say something...")
    st.write("Received from component:", value)