This example demonstrates the advanced power of the Piopiy Voice AI Orchestrator's native ServiceSwitcher.
Using a custom tool called manualswitch, the Voice Agent has the ability to change its own brain—or in this case, its Text-to-Speech (TTS) voice—on the fly mid-conversation based on user requests!
- We initialize two different TTS services (Cartesia and ElevenLabs).
- We wrap them in a
ServiceSwitcher(strategy_type=ServiceSwitcherStrategyManual). - We define a tool that the LLM can call to trigger
await voice_agent.switch_service(target_service).
You must install the SDK with the relevant provider extras:
pip install "piopiy-ai[cartesia,deepgram,openai,elevenlabs,silero]" python-dotenvYour .env file must contain these keys:
AGENT_ID="your_agent_id"
AGENT_TOKEN="your_agent_token"
OPENAI_API_KEY="your_openai_key"
DEEPGRAM_API_KEY="your_deepgram_key"
CARTESIA_API_KEY="your_cartesia_key"
ELEVENLABS_API_KEY="your_elevenlabs_key"Start the worker script to handle incoming calls:
python tts_switch.py- Log in to the Piopiy Dashboard.
- Ensure you have purchased a Piopiy phone number and mapped it to your new AI Agent.
- Dial that phone number from your personal phone to interact with your local agent!
Try asking the agent to "change to the British voice" or "switch to the ElevenLabs voice"!