|
import gradio as gr |
|
import speech_recognition as sr |
|
from pydub import AudioSegment |
|
|
|
|
|
recognizer = sr.Recognizer() |
|
|
|
def transcribe_audio(audio): |
|
try: |
|
|
|
audio_data = AudioSegment.from_file(audio) |
|
audio_data.export("audio.wav", format="wav") |
|
|
|
|
|
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)}" |
|
|
|
|
|
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") |
|
|
|
|
|
submit_button.click(fn=transcribe_audio, inputs=[audio_input], outputs=[output_text]) |
|
|
|
|
|
demo.launch() |