is it possible to send text input to the avatar an...
# ask-ai
r
is it possible to send text input to the avatar and have it respond? give me example code
t
Thanks for reaching out, Prince. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To send text input to an avatar and receive a response in LiveKit, you can use text streams. Here's a simple example to help you get started: Frontend (JavaScript):
Copy code
const text = "Hello, how are you?";
const info = await room.localParticipant.sendText(text, {
  topic: 'lk.chat',
});
console.log(`Sent text with stream ID: ${info.id}`);
Agent (Python):
Copy code
from livekit.agents import AgentSession, JobContext
from livekit.plugins import openai

async def entrypoint(ctx: JobContext):
    session = AgentSession(llm=openai.LLM(model="gpt-4o-mini"))
    await session.start(
        room=ctx.room,
        room_input_options=RoomInputOptions(text_enabled=True),
        room_output_options=RoomOutputOptions(transcription_enabled=True),
    )
    await session.generate_reply(user_input="Hi, can you help me?")
Frontend (Receiving Response):
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader) => {
  const message = await reader.readAll();
  console.log(`Avatar response: ${message}`);
});
If you have any questions or need more examples, please don’t hesitate to ask. I’m here to help you every step of the way! Sources: Text and transcriptions | LiveKit Docs | Sending text | LiveKit Docs | README.md | examples/avatar_agents/tavus/agent_worker.py | Docs::Agents