arshadrana commited on
Commit
fafa615
·
verified ·
1 Parent(s): 0fe9a40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -1,17 +1,21 @@
1
  import gradio as gr
2
  import speech_recognition as sr
 
3
 
4
  def transcribe_audio(audio_input):
5
  recognizer = sr.Recognizer()
6
-
7
- # Extract the file path from the Gradio audio input
8
- if isinstance(audio_input, tuple):
9
- audio_file_path = audio_input[0]
10
  else:
11
- raise ValueError("Expected audio_input to be a tuple, got {}".format(type(audio_input)))
12
 
13
- # Load the audio file
14
- with sr.AudioFile(audio_file_path) as source:
 
 
 
15
  audio_data = recognizer.record(source)
16
 
17
  try:
 
1
  import gradio as gr
2
  import speech_recognition as sr
3
+ from io import BytesIO
4
 
5
  def transcribe_audio(audio_input):
6
  recognizer = sr.Recognizer()
7
+
8
+ # Ensure the input is a tuple and get the audio data bytes
9
+ if isinstance(audio_input, tuple) and len(audio_input) == 2:
10
+ audio_data_bytes = audio_input[1]
11
  else:
12
+ raise ValueError("Expected audio_input to be a tuple with audio data bytes.")
13
 
14
+ # Use BytesIO to create a file-like object from the audio bytes
15
+ audio_file = BytesIO(audio_data_bytes)
16
+
17
+ # Load the audio file from the file-like object
18
+ with sr.AudioFile(audio_file) as source:
19
  audio_data = recognizer.record(source)
20
 
21
  try: