Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import speech_recognition as sr
|
|
| 3 |
|
| 4 |
def speech_to_text_from_file(audio_file):
|
| 5 |
recognizer = sr.Recognizer()
|
| 6 |
-
|
| 7 |
try:
|
| 8 |
with sr.AudioFile(audio_file) as source:
|
| 9 |
audio = recognizer.record(source)
|
|
@@ -11,14 +11,14 @@ def speech_to_text_from_file(audio_file):
|
|
| 11 |
return text
|
| 12 |
except sr.UnknownValueError:
|
| 13 |
return "❌ Could not understand the audio."
|
| 14 |
-
except sr.RequestError
|
| 15 |
-
return
|
| 16 |
except Exception as e:
|
| 17 |
-
return f"❌
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=speech_to_text_from_file,
|
| 21 |
-
inputs=gr.Audio(
|
| 22 |
outputs=gr.Textbox(label="Transcribed Text"),
|
| 23 |
title="🗣️ Speech-to-Text Converter",
|
| 24 |
description="Upload an audio file (WAV, FLAC, AIFF) to get a text transcription using Google Speech Recognition.",
|
|
@@ -26,4 +26,4 @@ iface = gr.Interface(
|
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
-
iface.launch(
|
|
|
|
| 3 |
|
| 4 |
def speech_to_text_from_file(audio_file):
|
| 5 |
recognizer = sr.Recognizer()
|
| 6 |
+
|
| 7 |
try:
|
| 8 |
with sr.AudioFile(audio_file) as source:
|
| 9 |
audio = recognizer.record(source)
|
|
|
|
| 11 |
return text
|
| 12 |
except sr.UnknownValueError:
|
| 13 |
return "❌ Could not understand the audio."
|
| 14 |
+
except sr.RequestError:
|
| 15 |
+
return "❌ API unavailable or internet issue."
|
| 16 |
except Exception as e:
|
| 17 |
+
return f"❌ Error: {str(e)}"
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=speech_to_text_from_file,
|
| 21 |
+
inputs=gr.Audio(type="filepath", label="Upload Audio File (WAV/FLAC/AIFF)"),
|
| 22 |
outputs=gr.Textbox(label="Transcribed Text"),
|
| 23 |
title="🗣️ Speech-to-Text Converter",
|
| 24 |
description="Upload an audio file (WAV, FLAC, AIFF) to get a text transcription using Google Speech Recognition.",
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
+
iface.launch()
|