File size: 1,189 Bytes
0255c8f
 
 
 
 
 
 
 
 
7f8f5d6
 
0255c8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f8f5d6
0255c8f
 
 
 
 
 
 
 
7f8f5d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()