Skip to navigation

change_voice

View as MarkdownOpen in Claude

Change the agent’s voice for the rest of the call. The new voice replaces the current language’s voice from the next batch of speech on, never in the middle of an utterance, and stays with that language for the rest of the call. It can be on a different TTS engine from the current voice.

Pass a list to give fallbacks: the first voice speaks, and the platform tries the others in order when it fails. When every voice in the list fails, the platform moves on to the agent’s fallback voices.

Parameters

voice
str | Sequence[str]Required

One voice in the engine.voice:model form a language’s voice takes, such as "elevenlabs.rachel" (see add_language() and the SWML languages reference), or a list of up to 8 of them. A one-item list is sent as a list.

Returns

FunctionResult — self, for chaining.

Raises

ValueError for an empty string, an empty list, more than 8 voices, or a list entry that isn’t a non-empty string.

Example

from signalwire import AgentBase, FunctionResult
agent = AgentBase(name="support", route="/support")
agent.set_prompt_text("You answer support calls.")
agent.add_language("English", "en-US", ["elevenlabs.rachel:eleven_flash_v2_5", "cartesia.kurt"])
@agent.tool(name="calmer_voice", description="Switch to a calmer voice")
def calmer_voice(args, raw_data):
return FunctionResult("Switching voices.").change_voice(
["elevenlabs.josh", "cartesia.kurt"]
)
agent.serve()

calmer_voice returns:

{"response": "Switching voices.",
"action": [{"change_voice": ["elevenlabs.josh", "cartesia.kurt"]}]}