Ramzan0553 commited on
Commit
061a46e
·
verified ·
1 Parent(s): e2c3f9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
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 as e:
15
- return f"❌ API request error: {str(e)}"
16
  except Exception as e:
17
- return f"❌ General error: {str(e)}"
18
 
19
  iface = gr.Interface(
20
  fn=speech_to_text_from_file,
21
- inputs=gr.Audio(source="upload", 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,4 +26,4 @@ iface = gr.Interface(
26
  )
27
 
28
  if __name__ == "__main__":
29
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
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()