# Issue with programmatically toggle STT/TTS on off

**URL:** <https://community.livekit.io/t/issue-with-programmatically-toggle-stt-tts-on-off/363>\
**Category:** Agents\
**Tags:** agent-development, python, stt, tts\
**Created:** [February 23, 2026, 12:05pm UTC](https://community.livekit.io/t/issue-with-programmatically-toggle-stt-tts-on-off/363 "2026-02-23T12:05:23Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [February 24, 2026, 9:17am UTC](https://community.livekit.io/t/issue-with-programmatically-toggle-stt-tts-on-off/363/6 "2026-02-24T09:17:06Z")

</div>

OK, for [agents/examples/voice\_agents/toggle\_io.py at main · livekit/agents · GitHub](https://github.com/livekit/agents/blob/main/examples/voice_agents/toggle_io.py) , when I connect to a room I see the following exception:

`Exception: cannot access local participant before connecting`

I will need to fix that in the sample, but the fix is to add:

` await ctx.connect()`

Immediately after `await session.start(…)`

After you apply that fix and connect to a room, it should work. You can test it as follows:

1. Start the agent `uv run examples/voice_agents/toggle_io.py dev`
2. Use the Agents Playground as a front end: [https://agents-playground.livekit.io/](https://agents-playground.livekit.io/)
3. Press `Connect` in the Playground and allow the agent to connect to your toom
4. Under the `RPC` options in the playground specify the method name as `toggle_input` and then the Payload is either `audio_off` or `audio_on` - you should see the agent stops or starts responding to your speech.
5. The example is written with the OpenAI realtime LLM, but it should work with any LLM/STT/TTS - you’ll need to modify it to match your setup if you don’t have an OpenAI key

---

_[View the full topic](https://community.livekit.io/t/issue-with-programmatically-toggle-stt-tts-on-off/363)._
