Hello Team,
I’m trying to call the function pronunciation_assessment_from_microphone() but after assesing for the first time it is displaying like this.
After the user enter the input and speaks the entered text.
It should ask for the next time but it is exiting
import azure.cognitiveservices.speech as speechsdk
import sys
import streamlit as st
import time
def pronunciation_assessment_from_microphone():
“”"“performs one-shot pronunciation assessment asynchronously with input from microphone.”""
config = speechsdk.SpeechConfig(subscription="", region="")
# The pronunciation assessment service has a longer default end silence timeout (5 seconds) than normal STT
# as the pronunciation assessment is widely used in education scenario where kids have longer break in reading.
# You can adjust the end silence timeout based on your real scenario.
config.set_property(speechsdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, "3000")
reference_text = ""
# create pronunciation assessment config, set grading system, granularity and if enable miscue based on your requirement.
pronunciation_config = speechsdk.PronunciationAssessmentConfig(reference_text=reference_text,
grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
granularity=speechsdk.PronunciationAssessmentGranularity.Phoneme,
enable_miscue=True)
st.markdown("### Reading Fluency Check")
recognizer = speechsdk.SpeechRecognizer(speech_config=config)
while True:
# Receives reference text from console input.
st.success('Enter reference text you want to assess, or enter stop to exit.')
try:
reference_text = st.text_input("Enter your text","")
if reference_text == "stop":
st.success('Entered stop to exit')
sys.exit(0)
except EOFError:
break
pronunciation_config.reference_text = reference_text
pronunciation_config.apply_to(recognizer)
# Starts recognizing.
st.success('Read out "{}" for pronunciation assessment ...'.format(reference_text))
# Note: Since recognize_once() returns only a single utterance, it is suitable only for single
# shot evaluation.
# For long-running multi-utterance pronunciation evaluation, use start_continuous_recognition() instead.
result = recognizer.recognize_once_async().get()
# Check the result
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
st.success('Recognized: {}'.format(result.text))
st.success(' Pronunciation Assessment Result:')
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
st.info(st.info('Accuracy Score : {}'.format(pronunciation_result.accuracy_score)))
st.info(st.info('Pronunciation Score : {}'.format(pronunciation_result.pronunciation_score)))
st.info(st.info('Completeness Score : {}'.format(pronunciation_result.completeness_score)))
st.info(st.info('Fluency Score : {}'.format(pronunciation_result.fluency_score)))
st.success(' Word-level details:')
for idx, word in enumerate(pronunciation_result.words):
st.info(' {}: word: {}, accuracy score: {}, error type: {};'.format(
idx + 1, word.word, word.accuracy_score, word.error_type
))
elif result.reason == speechsdk.ResultReason.NoMatch:
st.warning("No speech could be recognized")
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
st.error("Speech Recognition canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
st.error("Error details: {}".format(cancellation_details.error_details))
start=st.sidebar.checkbox(“Start”)
if start:
pronunciation_assessment_from_microphone()
time.sleep(10)
can you help me