From c19be6ebb2691ed1dab0cb26e2447a3d1a3e5fec Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Fri, 2 May 2025 19:50:56 -0400 Subject: [PATCH] Demo fixes --- examples/foundational/13c-gladia-translation.py | 3 ++- .../35-pattern-pair-voice-switching.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/foundational/13c-gladia-translation.py b/examples/foundational/13c-gladia-translation.py index 8ebd17aa4..0c821df5d 100644 --- a/examples/foundational/13c-gladia-translation.py +++ b/examples/foundational/13c-gladia-translation.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: BSD 2-Clause License # +import argparse import os from dotenv import load_dotenv @@ -39,7 +40,7 @@ class TranscriptionLogger(FrameProcessor): print(f"Translation ({frame.language}): {frame.text}") -async def run_bot(webrtc_connection: SmallWebRTCConnection): +async def run_bot(webrtc_connection: SmallWebRTCConnection, _: argparse.Namespace): logger.info(f"Starting bot") transport = SmallWebRTCTransport( diff --git a/examples/foundational/35-pattern-pair-voice-switching.py b/examples/foundational/35-pattern-pair-voice-switching.py index b99b543a9..07fadda26 100644 --- a/examples/foundational/35-pattern-pair-voice-switching.py +++ b/examples/foundational/35-pattern-pair-voice-switching.py @@ -45,6 +45,7 @@ Note: """ import argparse +import asyncio import os from dotenv import load_dotenv @@ -102,8 +103,17 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection, _: argparse.Namespac voice_name = match.content.strip().lower() if voice_name in VOICE_IDS: voice_id = VOICE_IDS[voice_name] - tts.set_voice(voice_id) - logger.info(f"Switched to {voice_name} voice") + + # Create task to reset the TTS context after voice change + async def change_voice(): + # First flush any existing audio to finish the current context + await tts.flush_audio() + # Then set the new voice + tts.set_voice(voice_id) + logger.info(f"Switched to {voice_name} voice") + + # Schedule the voice change task + asyncio.create_task(change_voice()) else: logger.warning(f"Unknown voice: {voice_name}")