import gradio as gr from scipy.io import wavfile from wav2vec_aligen import speaker_pronunciation_assesment def analyze_audio(audio): # Write the processed audio to a temporary WAV file if audio is None: return 'the audio is missing' temp_filename = 'temp_audio.wav' wavfile.write(temp_filename, audio[0], audio[1]) result = speaker_pronunciation_assesment(temp_filename) accuracy_score = result['pronunciation_accuracy'] fluency_score = result['fluency_score'] total_score = result['total_score'] content_scores = result['content_scores'] result_markdown = f"""|Language Aspect| Score| |---|---| |Pronunciation Accuracy| {accuracy_score}| |Fluency| {fluency_score}| |Total Score| {total_score}| |Content Score| {content_scores}| """ return result_markdown import gradio as gr CHOICES = ['Daibers', 'Carbon', 'Reptiles'] def get_paired_text(value): text = f'## {value}' return text with gr.Blocks() as demo: with gr.Row(): with gr.Column(): with gr.Row(): drp_down = gr.Dropdown(choices=CHOICES, scale=2) show_text_btn = gr.Button("Select", scale=1) read_text = gr.Markdown(label='Listen to speech') show_text_btn.click(get_paired_text, inputs=drp_down, outputs=read_text) audio_area = gr.Audio(label='Reapet the sentence') analyize_audio_btn = gr.Button("Submit", scale=1) with gr.Column(): capt_area = gr.Markdown(label='CAPT Scores') analyize_audio_btn.click(analyze_audio, inputs=audio_area, outputs=capt_area) demo.launch()