Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
8 |
-
if isinstance(audio_input, tuple):
|
9 |
-
|
10 |
else:
|
11 |
-
raise ValueError("Expected audio_input to be a tuple
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
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:
|