import gradio as gr import speech_recognition as sr from pydub import AudioSegment # Initialize the recognizer recognizer = sr.Recognizer() def transcribe_audio(audio): try: # Load the audio and convert to WAV format if necessary audio_data = AudioSegment.from_file(audio) audio_data.export("audio.wav", format="wav") # Use recognizer to transcribe the audio with sr.AudioFile("audio.wav") as source: audio_content = recognizer.record(source) transcription = recognizer.recognize_google(audio_content) return transcription except Exception as e: return f"Error: {str(e)}" # Create the Gradio interface with gr.Blocks() as demo: gr.Markdown("# Lecture Note Transcription App") with gr.Row(): audio_input = gr.Audio(type="filepath", label="Upload or Record Lecture Audio") output_text = gr.Textbox(label="Transcription", lines=10) submit_button = gr.Button("Transcribe") # Link the transcribe function to Gradio components submit_button.click(fn=transcribe_audio, inputs=[audio_input], outputs=[output_text]) # Launch the Gradio app demo.launch()