Nguyen5 commited on
Commit
6b33840
·
1 Parent(s): 77c7f90
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -658,6 +658,8 @@ with gr.Blocks(title="Prüfungsrechts-Chatbot (RAG + Sprache) - Enhanced") as de
658
  """Xử lý khi audio thay đổi"""
659
  if audio_path:
660
  print(f"DEBUG: Audio changed: {audio_path}")
 
 
661
  # Xử lý streaming
662
  text, vad_html, status = handle_audio_stream(audio_path, use_vad)
663
  return text, vad_html, status
@@ -669,6 +671,18 @@ with gr.Blocks(title="Prüfungsrechts-Chatbot (RAG + Sprache) - Enhanced") as de
669
  outputs=[chat_text, vad_indicator, status_display]
670
  )
671
 
 
 
 
 
 
 
 
 
 
 
 
 
672
  # Streaming handler removed; process on change after user stops recording
673
 
674
  # TTS Button
 
658
  """Xử lý khi audio thay đổi"""
659
  if audio_path:
660
  print(f"DEBUG: Audio changed: {audio_path}")
661
+ # Lưu lại đường dẫn bản ghi để nút Gửi có thể dùng
662
+ state.current_audio_path = audio_path
663
  # Xử lý streaming
664
  text, vad_html, status = handle_audio_stream(audio_path, use_vad)
665
  return text, vad_html, status
 
671
  outputs=[chat_text, vad_indicator, status_display]
672
  )
673
 
674
+ # Process immediately when user stops recording
675
+ def on_audio_stop(audio_path, history, lang_sel, use_vad):
676
+ print(f"DEBUG: stop_recording with audio_path={audio_path}")
677
+ state.current_audio_path = audio_path
678
+ return chat_fn("", audio_path, history, lang_sel, use_vad)
679
+
680
+ chat_audio.stop_recording(
681
+ on_audio_stop,
682
+ inputs=[chat_audio, chatbot, lang_selector, vad_toggle],
683
+ outputs=[chatbot, chat_text, chat_audio, status_display]
684
+ )
685
+
686
  # Streaming handler removed; process on change after user stops recording
687
 
688
  # TTS Button