Spaces:
Running
Running
FauziIsyrinApridal
commited on
Commit
Β·
d1c1b9c
1
Parent(s):
22ea197
update chat.py audio dijalankan dua kali dan klik aktif/nonaktif dua kali
Browse files- 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 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
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']
|
|
|
|
|
|