Color speech recognition

Download this notebook from GitHub (right-click to download).


In [ ]:
import panel as pn

from panel.widgets import SpeechToText, GrammarList

pn.extension()
In [ ]:
speech_to_text_color = SpeechToText(button_type="light", continuous=True)

colors = [
    "aqua",
    "azure",
    "beige",
    "bisque",
    "black",
    "blue",
    "brown",
    "chocolate",
    "coral",
    "crimson",
    "cyan",
    "fuchsia",
    "ghostwhite",
    "gold",
    "goldenrod",
    "gray",
    "green",
    "indigo",
    "ivory",
    "khaki",
    "lavender",
    "lime",
    "linen",
    "magenta",
    "maroon",
    "moccasin",
    "navy",
    "olive",
    "orange",
    "orchid",
    "peru",
    "pink",
    "plum",
    "purple",
    "red",
    "salmon",
    "sienna",
    "silver",
    "snow",
    "tan",
    "teal",
    "thistle",
    "tomato",
    "turquoise",
    "violet",
    "white",
    "yellow",
]
src = "#JSGF V1.0; grammar colors; public <color> = " + " | ".join(colors) + " ;"
grammar_list = GrammarList()
grammar_list.add_from_string(src, 1)

speech_to_text_color.grammars = grammar_list

colors_html = ", ".join(
    [f"<span style='background:{color};'>{color}</span>" for color in colors]
)
content_html = f"""
<h1>Speech Color Changer</h1>

<p>Tap/click the microphone icon and say a color to change the background color of the app. Try {colors_html}
"""

content_panel = pn.pane.HTML(content_html, sizing_mode="stretch_width")

app = pn.Column(height=500, width=500, css_classes=["color-app"])
style_panel = pn.pane.HTML(width=0, height=0, sizing_mode="fixed")

result_panel = pn.pane.Markdown(sizing_mode="stretch_width")

@pn.depends(speech_to_text_color, watch=True)
def update_result_panel(results_last):
    results_last = results_last.lower()
    if results_last in colors:
        app.background = results_last
        result_panel.object = "Result received: " + results_last
    else:
        app.background = "white"
        result_panel.object = "Result received: " + results_last + " (Not recognized)"

app[:] = [
    style_panel,
    content_panel,
    speech_to_text_color,
    result_panel,
]

app.servable()
In [ ]:
 
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).