import gradio as gr from logic import compare_audio_with_text from scipy.io import wavfile def create_html_from_scores(word_scores): html_output = '' # Ensure the number of words and scores match for word, score in word_scores: if score == 1: html_output += f'{word} ' elif score == 2: html_output += f'{word} ' else: html_output += f'{word} ' return html_output def analyze_audio(text, audio): # Write the processed audio to a temporary WAV file temp_filename = 'temp_audio.wav' wavfile.write(temp_filename, audio[0], audio[1]) result = compare_audio_with_text(temp_filename, text) html_content = create_html_from_scores(result) html_with_css = f"""
Good Understandable Bad

{html_content}

""" return html_with_css # Define the Gradio interface iface = gr.Interface(fn=analyze_audio, inputs=[gr.Textbox(label='Training Text', placeholder='Write the text for pronunciation task', interactive=True, visible=True, show_copy_button=True,), gr.Audio(label="Upload Audio") ], outputs=[gr.HTML(label="Analysis of pronunciation"), ], # css=additional_css, # title="Audio Analysis Tool", description="Upload an audio file to analyze pronunciation accuracy and speech fluency." ) # Run the Gradio app if __name__ == "__main__": iface.launch()