Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
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()
|
@@ -14,8 +15,14 @@ def transcribe_audio(audio_input):
|
|
14 |
# Use BytesIO to create a file-like object from the audio bytes
|
15 |
audio_file = BytesIO(audio_data_bytes)
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
audio_data = recognizer.record(source)
|
20 |
|
21 |
try:
|
|
|
1 |
import gradio as gr
|
2 |
import speech_recognition as sr
|
3 |
from io import BytesIO
|
4 |
+
from pydub import AudioSegment
|
5 |
|
6 |
def transcribe_audio(audio_input):
|
7 |
recognizer = sr.Recognizer()
|
|
|
15 |
# Use BytesIO to create a file-like object from the audio bytes
|
16 |
audio_file = BytesIO(audio_data_bytes)
|
17 |
|
18 |
+
# Convert audio to WAV format using pydub
|
19 |
+
audio_segment = AudioSegment.from_file(audio_file)
|
20 |
+
wav_io = BytesIO()
|
21 |
+
audio_segment.export(wav_io, format="wav")
|
22 |
+
wav_io.seek(0) # Move to the beginning of the file-like object
|
23 |
+
|
24 |
+
# Load the audio file from the file-like object in WAV format
|
25 |
+
with sr.AudioFile(wav_io) as source:
|
26 |
audio_data = recognizer.record(source)
|
27 |
|
28 |
try:
|