gaur3009 commited on
Commit
14335b6
·
verified ·
1 Parent(s): ddabc71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import speech_recognition as sr
3
+
4
+ # Speech-to-text conversion function
5
+ def transcribe_audio(audio):
6
+ recognizer = sr.Recognizer()
7
+ with sr.AudioFile(audio) as source:
8
+ audio_data = recognizer.record(source)
9
+ try:
10
+ text = recognizer.recognize_google(audio_data)
11
+ return text
12
+ except sr.UnknownValueError:
13
+ return "Could not understand the audio."
14
+ except sr.RequestError as e:
15
+ return f"Speech recognition error: {e}"
16
+
17
+ # Gradio UI
18
+ def main():
19
+ iface = gr.Interface(
20
+ fn=transcribe_audio,
21
+ inputs=gr.Audio(sources=["microphone"], type="filepath", label="Speak something"),
22
+ outputs=gr.Textbox(label="Transcribed Text"),
23
+ title="Speech-to-Text Demo",
24
+ description="Speak into the microphone and see the transcribed text below.",
25
+ live=False
26
+ )
27
+ iface.launch()
28
+
29
+ if __name__ == "__main__":
30
+ main()