Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,11 @@ import tempfile
|
|
2 |
import webrtcvad
|
3 |
import speech_recognition as sr
|
4 |
import os
|
5 |
-
import
|
|
|
6 |
|
7 |
def update_vad_status(status):
|
8 |
-
|
9 |
|
10 |
def process_audio_file(audio_file_path):
|
11 |
# Configuramos la tasa de muestreo y el tamaño del frame
|
@@ -26,8 +27,11 @@ def process_audio_file(audio_file_path):
|
|
26 |
with open(audio_file_path, "rb") as f:
|
27 |
audio_data = f.read()
|
28 |
|
29 |
-
except FileNotFoundError:
|
30 |
-
|
|
|
|
|
|
|
31 |
return
|
32 |
|
33 |
# 2. Use a temporary file to process the audio data:
|
@@ -64,27 +68,22 @@ def process_audio_file(audio_file_path):
|
|
64 |
try:
|
65 |
text = recognizer.recognize_google(audio)
|
66 |
phrase += f" {text}"
|
67 |
-
|
68 |
except sr.RequestError:
|
69 |
-
|
70 |
except sr.UnknownValueError:
|
71 |
-
|
72 |
|
73 |
# Reiniciamos el indicador de frase
|
74 |
speech_detected = False
|
75 |
|
76 |
# Imprimimos la frase completa
|
77 |
-
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
root.title("VAD Status")
|
82 |
|
83 |
-
|
84 |
-
vad_status_label.pack(pady=20)
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
process_audio_file(audio_file_path)
|
89 |
-
|
90 |
-
root.mainloop()
|
|
|
2 |
import webrtcvad
|
3 |
import speech_recognition as sr
|
4 |
import os
|
5 |
+
import streamlit as st
|
6 |
+
from traceback import format_exc
|
7 |
|
8 |
def update_vad_status(status):
|
9 |
+
vad_status.text(status)
|
10 |
|
11 |
def process_audio_file(audio_file_path):
|
12 |
# Configuramos la tasa de muestreo y el tamaño del frame
|
|
|
27 |
with open(audio_file_path, "rb") as f:
|
28 |
audio_data = f.read()
|
29 |
|
30 |
+
except FileNotFoundError as e:
|
31 |
+
st.error(f"Error: File not found - {audio_file_path}")
|
32 |
+
st.error(f"Error Details: {e}")
|
33 |
+
st.error("Traceback:")
|
34 |
+
st.error(format_exc())
|
35 |
return
|
36 |
|
37 |
# 2. Use a temporary file to process the audio data:
|
|
|
68 |
try:
|
69 |
text = recognizer.recognize_google(audio)
|
70 |
phrase += f" {text}"
|
71 |
+
st.text(f"️ {text}")
|
72 |
except sr.RequestError:
|
73 |
+
st.error("⚠️ Error al transcribir la frase - RequestError")
|
74 |
except sr.UnknownValueError:
|
75 |
+
st.error("⚠️ No se ha reconocido la frase - UnknownValueError")
|
76 |
|
77 |
# Reiniciamos el indicador de frase
|
78 |
speech_detected = False
|
79 |
|
80 |
# Imprimimos la frase completa
|
81 |
+
st.success(f"Transcripción completa: {phrase}")
|
82 |
|
83 |
+
# Streamlit UI
|
84 |
+
st.title("VAD and Speech Recognition App")
|
|
|
85 |
|
86 |
+
uploaded_file = st.file_uploader("Choose an audio file", type=["wav"])
|
|
|
87 |
|
88 |
+
if uploaded_file:
|
89 |
+
process_audio_file(uploaded_file.name)
|
|
|
|
|
|