Spaces:
Sleeping
Sleeping
FauziIsyrinApridal
commited on
Commit
·
498342f
1
Parent(s):
882e3b8
update chat.py audio dijalankan selang seling
Browse files- app/chat.py +4 -5
app/chat.py
CHANGED
@@ -62,11 +62,9 @@ def display_chat_history(chain):
|
|
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:
|
72 |
stt_text = speech_to_text(
|
@@ -97,6 +95,8 @@ def display_chat_history(chain):
|
|
97 |
# Simpan output untuk TTS
|
98 |
if st.session_state['should_speak'] and output:
|
99 |
st.session_state['tts_output'] = output
|
|
|
|
|
100 |
|
101 |
# Tampilkan riwayat chat
|
102 |
if st.session_state['generated']:
|
@@ -106,10 +106,9 @@ def display_chat_history(chain):
|
|
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'
|
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'
|
113 |
-
# Reset state setelah audio selesai
|
114 |
st.session_state['tts_output'] = ""
|
115 |
del st.session_state['tts_played']
|
|
|
62 |
key="toggle_tts",
|
63 |
help="Aktifkan/Nonaktifkan Text-to-Speech",
|
64 |
use_container_width=True):
|
|
|
65 |
st.session_state['should_speak'] = not st.session_state['should_speak']
|
66 |
st.experimental_rerun()
|
67 |
|
|
|
68 |
# Rekaman suara
|
69 |
with col3:
|
70 |
stt_text = speech_to_text(
|
|
|
95 |
# Simpan output untuk TTS
|
96 |
if st.session_state['should_speak'] and output:
|
97 |
st.session_state['tts_output'] = output
|
98 |
+
if 'tts_played' in st.session_state:
|
99 |
+
del st.session_state['tts_played']
|
100 |
|
101 |
# Tampilkan riwayat chat
|
102 |
if st.session_state['generated']:
|
|
|
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'):
|
110 |
st.markdown(text_to_speech(st.session_state['tts_output']), unsafe_allow_html=True)
|
111 |
st.session_state['tts_played'] = True
|
112 |
+
elif st.session_state.get('tts_played'):
|
|
|
113 |
st.session_state['tts_output'] = ""
|
114 |
del st.session_state['tts_played']
|