FauziIsyrinApridal commited on
Commit
d1c1b9c
Β·
1 Parent(s): 22ea197

update chat.py audio dijalankan dua kali dan klik aktif/nonaktif dua kali

Browse files
Files changed (1) hide show
  1. app/chat.py +14 -13
app/chat.py CHANGED
@@ -58,10 +58,14 @@ def display_chat_history(chain):
58
 
59
  # Tombol toggle suara
60
  with col2:
61
- should_speak = st.session_state.get('should_speak', True)
62
- icon_label = "πŸ”Š Text-to-Speech Aktif" if should_speak else "πŸ”‡ Text-to-Speech Nonaktif"
63
- if st.button(icon_label, key="toggle_tts", help="Aktifkan/Nonaktifkan Text-to-Speech", use_container_width=True):
64
- st.session_state['should_speak'] = not should_speak
 
 
 
 
65
 
66
  # Rekaman suara
67
  with col3:
@@ -102,13 +106,10 @@ def display_chat_history(chain):
102
  message(st.session_state["generated"][i], key=str(i), avatar_style="no-avatar")
103
 
104
  # Tampilkan dan mainkan audio TTS jika ada
105
- if st.session_state.get('tts_output'):
106
  st.markdown(text_to_speech(st.session_state['tts_output']), unsafe_allow_html=True)
107
-
108
- # Beri waktu render audio sebelum menghapus tts_output
109
- if 'tts_played' not in st.session_state:
110
- st.session_state['tts_played'] = True
111
- st.experimental_rerun()
112
- else:
113
- st.session_state['tts_output'] = ""
114
- del st.session_state['tts_played']
 
58
 
59
  # Tombol toggle suara
60
  with col2:
61
+ if st.button("πŸ”Š Text-to-Speech Aktif" if st.session_state['should_speak'] else "πŸ”‡ Text-to-Speech Nonaktif",
62
+ key="toggle_tts",
63
+ help="Aktifkan/Nonaktifkan Text-to-Speech",
64
+ use_container_width=True):
65
+ # Toggle state langsung
66
+ st.session_state['should_speak'] = not st.session_state['should_speak']
67
+ st.experimental_rerun()
68
+
69
 
70
  # Rekaman suara
71
  with col3:
 
106
  message(st.session_state["generated"][i], key=str(i), avatar_style="no-avatar")
107
 
108
  # Tampilkan dan mainkan audio TTS jika ada
109
+ if st.session_state.get('tts_output') and not st.session_state.get('tts_played', False):
110
  st.markdown(text_to_speech(st.session_state['tts_output']), unsafe_allow_html=True)
111
+ st.session_state['tts_played'] = True
112
+ elif 'tts_played' in st.session_state:
113
+ # Reset state setelah audio selesai
114
+ st.session_state['tts_output'] = ""
115
+ del st.session_state['tts_played']