import streamlit as st
import azure.cognitiveservices.speech as speechsdk
chunks = []
recognizer= None
subscription_key = "y"
service_region = "x"
speech_config = speechsdk.SpeechConfig(subscription=subscription_key, region=service_region)
audio_config = speechsdk.AudioConfig(use_default_microphone=True)
def recognized_callback(evt):
global chunks
k = False
global recognizer
while not k:
if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech:
rec_text =evt.result.text
if "Stop Muse" in rec_text :
k = True
print(f"Recognized End: {rec_text}")
recognizer.stop_continuous_recognition()
st.session_state['endResults'] = chunks
exit()
else:
chunks.append(rec_text)
print(f"Recognized: {rec_text}")
exit()
def main():
global recognizer
if 'endResults' not in st.session_state.keys():
st.session_state['endResults'] = []
st.title("Azure Speech Service with Streamlit")
#st.button("Start")
st.write("Speak into your microphone.")
if st.button("Start"):
recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
recognizer.recognized.connect(recognized_callback)
recognizer.start_continuous_recognition()
k=0
if __name__ == "__main__":
main()
print(st.session_state['endResults'])
I keep getting 2024-06-06 20:21:38.948 Thread ‘Dummy-1’: missing ScriptRunContext
2024-06-06 20:21:38.949 Thread ‘Dummy-1’: missing ScriptRunContext (With using session storage) but I don’t know what I am doing, these re renders make Azures continuous recognition useless, should I use something else outside of streamlit?