how do i prevent my agent from saying anything for...
# ask-ai
c
how do i prevent my agent from saying anything for a fixed amount of time using agentsession and voice pipeline?
t
Thanks for reaching out, Faraz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To prevent your agent from speaking for a fixed amount of time using AgentSession and Voice Pipeline, you can use the
min_consecutive_speech_delay
parameter when initializing your AgentSession. This enforces a minimum delay (in seconds) between consecutive speech utterances. Here’s an example:
Copy code
session = AgentSession(
    min_consecutive_speech_delay=5.0,  # 5-second delay between speech
    # other parameters...
)
Alternatively, you can implement custom logic for more granular control. For example:
Copy code
import asyncio

class TimedAgent(Agent):
    def __init__(self):
        super().__init__(
            # agent configuration...
        )
        self.last_speech_time = 0
        self.speech_delay = 5.0  # 5-second delay

    async def controlled_speech(self, text):
        current_time = time.time()
        time_since_last = current_time - self.last_speech_time

        if time_since_last < self.speech_delay:
            wait_time = self.speech_delay - time_since_last
            await asyncio.sleep(wait_time)

        await self.session.say(text, allow_interruptions=False)
        self.last_speech_time = time.time()
You can also explore endpointing delays for additional control:
Copy code
session = AgentSession(
    min_endpointing_delay=2.0,  # Wait 2 seconds after potential end-of-utterance
    max_endpointing_delay=8.0,  # Maximum wait time before terminating turn
    # other parameters...
)
The
min_consecutive_speech_delay
parameter is the simplest and most direct method to enforce a fixed delay between agent speech utterances. Sources: tests/test_agent_session.py | basics/uninterruptable.py