Imarticuslearning commited on
Commit
2bbc1b4
·
verified ·
1 Parent(s): d152d8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -40
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("🎙️ Record your answer (tap when done)", key=f"audio_{idx}")
873
-
874
- if audio_bytes:
875
- wav_path = f"response_{idx}.wav"
876
- with open(wav_path, "wb") as f:
877
- f.write(audio_bytes.getbuffer())
878
- st.audio(wav_path)
879
- st.session_state["answers"].append({
880
- "question": question,
881
- "response_file": wav_path
882
- })
883
-
884
- if webrtc_ctx.state.playing:
885
- if st.button("⏹️ Stop Recording"):
886
- wav_path = f"response_{idx}.wav"
887
- try:
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
- if frames:
894
- try:
895
- pcm = np.concatenate([f.to_ndarray() for f in frames], axis=0)
896
- sample_rate = frames[0].sample_rate
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",