Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -869,49 +869,30 @@ if st.session_state["generated_questions"]:
|
|
| 869 |
if remaining > 0:
|
| 870 |
st.markdown(f"<h4 class='timer-text'>🎙️ {remaining} seconds to answer...</h4>", unsafe_allow_html=True)
|
| 871 |
|
| 872 |
-
audio_bytes = st.audio_input("🎙️
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
frames = webrtc_ctx.audio_receiver.get_frames(timeout=1)
|
| 889 |
-
except Exception as e:
|
| 890 |
-
st.error(f"⚠️ Audio capture error: {e}")
|
| 891 |
-
frames = []
|
| 892 |
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
sf.write(wav_path, pcm, sample_rate)
|
| 898 |
-
st.audio(wav_path)
|
| 899 |
-
st.session_state["answers"].append({
|
| 900 |
-
"question": question,
|
| 901 |
-
"response_file": wav_path
|
| 902 |
-
})
|
| 903 |
-
except Exception as e:
|
| 904 |
-
st.error(f"⚠️ Error saving recording: {e}")
|
| 905 |
-
st.session_state["answers"].append({
|
| 906 |
-
"question": question,
|
| 907 |
-
"response": "[Error saving recording]"
|
| 908 |
-
})
|
| 909 |
-
else:
|
| 910 |
-
st.warning("⚠️ No audio captured.")
|
| 911 |
-
st.session_state["answers"].append({
|
| 912 |
"question": question,
|
| 913 |
"response": "[No response]"
|
| 914 |
-
|
| 915 |
|
| 916 |
st.session_state.update({
|
| 917 |
"record_phase": "idle",
|
|
|
|
| 869 |
if remaining > 0:
|
| 870 |
st.markdown(f"<h4 class='timer-text'>🎙️ {remaining} seconds to answer...</h4>", unsafe_allow_html=True)
|
| 871 |
|
| 872 |
+
audio_bytes = st.audio_input("🎙️ Tap to record your answer")
|
| 873 |
+
if audio_bytes:
|
| 874 |
+
wav_path = Path(f"response_{idx}.wav")
|
| 875 |
+
wav_path.write_bytes(audio_bytes.getbuffer())
|
| 876 |
+
st.audio(str(wav_path))
|
| 877 |
+
st.session_state["answers"].append({
|
| 878 |
+
"question": question,
|
| 879 |
+
"response_file": str(wav_path)
|
| 880 |
+
})
|
| 881 |
+
|
| 882 |
+
st.session_state.update({
|
| 883 |
+
"current_question_index": idx + 1,
|
| 884 |
+
"question_played": False,
|
| 885 |
+
"record_phase": "audio_playing"
|
| 886 |
+
})
|
| 887 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 888 |
|
| 889 |
+
|
| 890 |
+
else:
|
| 891 |
+
st.warning("⚠️ No audio captured.")
|
| 892 |
+
st.session_state["answers"].append({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
"question": question,
|
| 894 |
"response": "[No response]"
|
| 895 |
+
})
|
| 896 |
|
| 897 |
st.session_state.update({
|
| 898 |
"record_phase": "idle",
|