I've a voicepipelineagent created in python, which...
# ask-ai
a
I've a voicepipelineagent created in python, which connects to human who's connecting in a room, and using TTS he listens to bot voice. I want to invite another human agent in the same room, who will control the TTS output being generated... how can I do that?
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to invite another human agent to a LiveKit room and let them control the TTS output, here’s a simple way to do it: 1. Create an Access Token: First, you’ll need to generate an access token that gives the agent permission to join the room and publish audio. You can use the
livekit.AccessToken
class for this, making sure it includes the right grants for room access and publishing on behalf of someone else. 2. Launch the Agent: Next, use a function like
launch_avatar
to send the connection details (like the room name, server URL, and token) over to the agent. This usually means sending a POST request to the avatar dispatcher. 3. Control TTS Output: Once the agent is in the room, they can use handy methods like
session.say()
or
generate_reply()
to manage the TTS output. These let the agent specify what to say and handle any interruptions smoothly. Here’s a quick example of what the
launch_avatar
function might look like:
Copy code
async def launch_avatar(ctx: JobContext, avatar_dispatcher_url: str, avatar_identity: str):
    token = (
        api.AccessToken()
        .with_identity(avatar_identity)
        .with_name("Avatar Runner")
        .with_grants(api.VideoGrants(room_join=True, room=ctx.room.name))
        .with_kind("agent")
        .with_attributes({ATTRIBUTE_PUBLISH_ON_BEHALF: ctx.token_claims().identity})
        .to_jwt()
    )

    connection_info = AvatarConnectionInfo(room_name=ctx.room.name, url=ctx._info.url, token=token)
    async with httpx.AsyncClient() as client:
        response = await <http://client.post|client.post>(avatar_dispatcher_url, json=asdict(connection_info))
        response.raise_for_status()
If you want to dive deeper, check out the LiveKit docs on Agent Speech. They’ve got some great info to help you along!