Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,8 @@ from streamlit_webrtc import webrtc_streamer, WebRtcMode
|
|
| 18 |
from twilio.rest import Client
|
| 19 |
import logging
|
| 20 |
import whisper
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
# ✅ MUST be the first Streamlit command
|
|
@@ -878,12 +879,25 @@ if st.session_state["generated_questions"]:
|
|
| 878 |
wav_path = f"response_{idx}.wav"
|
| 879 |
with open(wav_path, "wb") as f:
|
| 880 |
f.write(audio_value.getbuffer())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
#st.audio(wav_path, format="audio/wav")
|
| 882 |
st.session_state["response_file"] = wav_path
|
| 883 |
st.session_state["record_phase"] = "listening"
|
| 884 |
st.success("✅ Audio uploaded. You may now confirm your answer.")
|
| 885 |
st.audio(wav_path, format="audio/wav")
|
| 886 |
-
|
| 887 |
if st.button("⏹️ Confirm & Next"):
|
| 888 |
try:
|
| 889 |
with st.spinner("🧠 Transcribing your answer..."):
|
|
@@ -895,6 +909,7 @@ if st.session_state["generated_questions"]:
|
|
| 895 |
except Exception as e:
|
| 896 |
st.error(f"❌ Transcription error: {e}")
|
| 897 |
transcript = "[Transcription error]"
|
|
|
|
| 898 |
|
| 899 |
st.session_state["answers"].append({
|
| 900 |
"question": question,
|
|
|
|
| 18 |
from twilio.rest import Client
|
| 19 |
import logging
|
| 20 |
import whisper
|
| 21 |
+
import speech_recognition as sr
|
| 22 |
+
#model = whisper.load_model("base")
|
| 23 |
|
| 24 |
|
| 25 |
# ✅ MUST be the first Streamlit command
|
|
|
|
| 879 |
wav_path = f"response_{idx}.wav"
|
| 880 |
with open(wav_path, "wb") as f:
|
| 881 |
f.write(audio_value.getbuffer())
|
| 882 |
+
recognizer = sr.Recognizer()
|
| 883 |
+
try:
|
| 884 |
+
with sr.AudioFile(wav_path) as source:
|
| 885 |
+
audio = recognizer.record(source)
|
| 886 |
+
transcript = recognizer.recognize_google(audio)
|
| 887 |
+
except sr.UnknownValueError:
|
| 888 |
+
transcript = "[Could not understand audio]"
|
| 889 |
+
except sr.RequestError:
|
| 890 |
+
transcript = "[Google API error]"
|
| 891 |
+
except Exception as e:
|
| 892 |
+
transcript = f"[Transcription failed: {e}]"
|
| 893 |
+
|
| 894 |
+
|
| 895 |
#st.audio(wav_path, format="audio/wav")
|
| 896 |
st.session_state["response_file"] = wav_path
|
| 897 |
st.session_state["record_phase"] = "listening"
|
| 898 |
st.success("✅ Audio uploaded. You may now confirm your answer.")
|
| 899 |
st.audio(wav_path, format="audio/wav")
|
| 900 |
+
"""
|
| 901 |
if st.button("⏹️ Confirm & Next"):
|
| 902 |
try:
|
| 903 |
with st.spinner("🧠 Transcribing your answer..."):
|
|
|
|
| 909 |
except Exception as e:
|
| 910 |
st.error(f"❌ Transcription error: {e}")
|
| 911 |
transcript = "[Transcription error]"
|
| 912 |
+
"""
|
| 913 |
|
| 914 |
st.session_state["answers"].append({
|
| 915 |
"question": question,
|