TuringsSolutions commited on
Commit
0255c8f
1 Parent(s): 3590f4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import speech_recognition as sr
3
+ from pydub import AudioSegment
4
+
5
+ # Initialize the recognizer
6
+ recognizer = sr.Recognizer()
7
+
8
+ def transcribe_audio(audio):
9
+ try:
10
+ # Convert audio input to .wav if needed
11
+ audio_data = AudioSegment.from_file(audio.name)
12
+ audio_data.export("audio.wav", format="wav")
13
+
14
+ # Use recognizer to transcribe the audio
15
+ with sr.AudioFile("audio.wav") as source:
16
+ audio_content = recognizer.record(source)
17
+ transcription = recognizer.recognize_google(audio_content)
18
+
19
+ return transcription
20
+ except Exception as e:
21
+ return f"Error: {str(e)}"
22
+
23
+ # Create the Gradio interface
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("# Lecture Note Transcription App")
26
+
27
+ with gr.Row():
28
+ audio_input = gr.Audio(source="microphone", type="filepath", label="Record Lecture Audio")
29
+ output_text = gr.Textbox(label="Transcription", lines=10)
30
+
31
+ submit_button = gr.Button("Transcribe")
32
+
33
+ # Link the transcribe function to Gradio components
34
+ submit_button.click(fn=transcribe_audio, inputs=[audio_input], outputs=[output_text])
35
+
36
+ # Launch the Gradio app
37
+ demo.launch()