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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -869,21 +869,17 @@ 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("🎙️ 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
 
@@ -922,17 +918,23 @@ if st.session_state["generated_questions"]:
922
  st.rerun()
923
 
924
  elif st.session_state["record_phase"] == "listening":
925
- st.success("🎧 Listening... You may stop when ready.")
926
- if st.button("⏹️ Stop Recording"):
927
- st.session_state["answers"].append({"question": question, "response": st.session_state["recorded_text"]})
 
 
 
 
 
 
928
  st.session_state.update({
929
  "record_phase": "idle",
930
- "recorded_text": "",
931
  "recording_started": False,
932
  "question_played": False,
933
  "question_start_time": 0.0,
934
  "current_question_index": idx + 1
935
  })
 
936
  if st.session_state["current_question_index"] == len(st.session_state["generated_questions"]):
937
  evaluate_answers()
938
  st.session_state["show_summary"] = True
 
869
  if remaining > 0:
870
  st.markdown(f"<h4 class='timer-text'>🎙️ {remaining} seconds to answer...</h4>", unsafe_allow_html=True)
871
 
872
+ audio_value = st.audio_input("🎤 Tap to record then stop when done", key=f"audio_{idx}")
873
+ if audio_value:
874
+ wav_path = f"response_{idx}.wav"
875
+ with open(wav_path, "wb") as f:
876
+ f.write(audio_value.getbuffer())
877
+ st.audio(wav_path, format="audio/wav")
 
 
 
878
 
879
  st.session_state.update({
880
+ "record_phase": "listening",
881
+ "response_file": wav_path,
882
+ })
 
883
  st.experimental_rerun()
884
 
885
 
 
918
  st.rerun()
919
 
920
  elif st.session_state["record_phase"] == "listening":
921
+ st.success("🎧 Review your response below:")
922
+ st.audio(st.session_state["response_file"], format="audio/wav")
923
+ if st.button("⏹️ Confirm & Next"):
924
+ st.session_state["answers"].append({
925
+ "question": question,
926
+ "response_file": st.session_state["response_file"],
927
+ "response_text": st.session_state.get("recorded_text", "")
928
+ })
929
+
930
  st.session_state.update({
931
  "record_phase": "idle",
 
932
  "recording_started": False,
933
  "question_played": False,
934
  "question_start_time": 0.0,
935
  "current_question_index": idx + 1
936
  })
937
+
938
  if st.session_state["current_question_index"] == len(st.session_state["generated_questions"]):
939
  evaluate_answers()
940
  st.session_state["show_summary"] = True