Spaces:
Sleeping
Sleeping
Akis Giannoukos
commited on
Commit
·
bceeb42
1
Parent(s):
eec3132
Add explicit user gesture to play intro TTS in demo interface, enhancing cross-browser compatibility. Refactor initialization to separate TTS loading logic.
Browse files
app.py
CHANGED
|
@@ -587,6 +587,15 @@ def _on_load_init_with_tts(tts_on: bool):
|
|
| 587 |
tts_path = synthesize_tts(chat_history[-1][1]) if bool(tts_on) else None
|
| 588 |
return chat_history, scores_state, meta_state, finished_state, turns_state, tts_path
|
| 589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
def create_demo():
|
| 591 |
with gr.Blocks(
|
| 592 |
theme=gr.themes.Soft(),
|
|
@@ -632,6 +641,7 @@ def create_demo():
|
|
| 632 |
Tap on 'Record' to start speaking, then tap on 'Stop' to stop recording.
|
| 633 |
"""
|
| 634 |
)
|
|
|
|
| 635 |
|
| 636 |
with gr.Tabs():
|
| 637 |
with gr.TabItem("Main"):
|
|
@@ -664,8 +674,11 @@ def create_demo():
|
|
| 664 |
finished_state = gr.State()
|
| 665 |
turns_state = gr.State()
|
| 666 |
|
| 667 |
-
# Initialize on load
|
| 668 |
-
demo.load(
|
|
|
|
|
|
|
|
|
|
| 669 |
|
| 670 |
# Wire interactions
|
| 671 |
audio_main.stop_recording(
|
|
|
|
| 587 |
tts_path = synthesize_tts(chat_history[-1][1]) if bool(tts_on) else None
|
| 588 |
return chat_history, scores_state, meta_state, finished_state, turns_state, tts_path
|
| 589 |
|
| 590 |
+
|
| 591 |
+
def _play_intro_tts(tts_on: bool):
|
| 592 |
+
if not bool(tts_on):
|
| 593 |
+
return None
|
| 594 |
+
try:
|
| 595 |
+
return synthesize_tts(INTRO_MESSAGE)
|
| 596 |
+
except Exception:
|
| 597 |
+
return None
|
| 598 |
+
|
| 599 |
def create_demo():
|
| 600 |
with gr.Blocks(
|
| 601 |
theme=gr.themes.Soft(),
|
|
|
|
| 641 |
Tap on 'Record' to start speaking, then tap on 'Stop' to stop recording.
|
| 642 |
"""
|
| 643 |
)
|
| 644 |
+
intro_play_btn = gr.Button("▶️ Play Intro", variant="secondary")
|
| 645 |
|
| 646 |
with gr.Tabs():
|
| 647 |
with gr.TabItem("Main"):
|
|
|
|
| 674 |
finished_state = gr.State()
|
| 675 |
turns_state = gr.State()
|
| 676 |
|
| 677 |
+
# Initialize on load (no autoplay due to browser policies)
|
| 678 |
+
demo.load(_on_load_init, inputs=None, outputs=[chatbot, scores_state, meta_state, finished_state, turns_state])
|
| 679 |
+
|
| 680 |
+
# Explicit user gesture to play intro TTS (works across browsers)
|
| 681 |
+
intro_play_btn.click(fn=_play_intro_tts, inputs=[tts_enable], outputs=[tts_audio_main])
|
| 682 |
|
| 683 |
# Wire interactions
|
| 684 |
audio_main.stop_recording(
|