voice doesnt exist in @livekit/agent-js
# ask-ai
r
voice doesnt exist in @livekit/agent-js
t
Thanks for reaching out, Hrithik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to share that the
@livekit/agent-js
package does include voice functionality! It comes with a dedicated
voice
module designed to help you build voice-based AI agents, featuring capabilities like speech-to-text (STT), text-to-speech (TTS), voice activity detection (VAD), and even integration with Large Language Models (LLM) for smooth conversational AI experiences. Here are some key components to know about: •
voice.Agent
: This lets you define agents with STT, TTS, LLM, and VAD configurations tailored to your needs. •
voice.AgentSession
: It manages the lifecycle of a voice agent within a LiveKit room, keeping things running smoothly. • Support for popular third-party STT and TTS services like Deepgram, ElevenLabs, and Google, giving you flexibility. • Turn detection and real-time audio processing to make your conversations interactive and natural. If you'd like, I’m here to help you set up or guide you through using any of these features—just let me know! Sources: examples/src/cartersia_tts.ts | Agent speech and audio | LiveKit Docs
r
yes please make me a guide in typescript
t
Here’s a friendly guide to help you set up a voice agent using
@livekit/agent-js
in TypeScript: 1. Define the Agent: Start by using the
defineAgent
function to create an entrypoint. This will also prewarm important resources like the Voice Activity Detection (VAD) model to get things ready:
Copy code
export default defineAgent({
  prewarm: async (proc) => {
    proc.userData.vad = await silero.VAD.load();
  },
  entry: async (ctx) => {
    // Agent setup and room connection happens here
  },
});
1. Set Up the Voice Agent: Next, create the agent with clear instructions and tools to make it friendly and effective:
Copy code
const agent = new voice.Agent({
  instructions: 'You are a friendly voice assistant built by LiveKit.',
});
1. Create and Start the Agent Session: Here, you’ll use the prewarmed VAD and other components to get the session going:
Copy code
const session = new voice.AgentSession({
  vad: ctx.proc.userData.vad,
  stt: new deepgram.STT(),
  llm: new openai.LLM(),
  tts: new elevenlabs.TTS(),
  turnDetection: new livekit.turnDetector.MultilingualModel(),
});

await session.start({
  agent,
  room: ctx.room,
});
1. Connect to the Room: Finally, join the LiveKit room as a participant and greet users warmly:
Copy code
await ctx.connect();
session.say('Hello, how can I help you today?');
If you have any questions or would like a complete example, please don’t hesitate to ask—I’m here to help! Sources: examples/src/drive-thru/drivethru_agent.ts
r
how to import it the import for voice
t
To get started with importing the voice module in
@livekit/agent-js
for TypeScript, you can use this simple line:
Copy code
import { voice } from '@livekit/agents';
This will give you access to important components like
Agent
and
AgentSession
, which are great for building voice-enabled agents. Just make sure you have the necessary dependencies installed by running:
Copy code
npm install @livekit/agents
npm install @livekit/agents-plugin-openai @livekit/agents-plugin-deepgram @livekit/agents-plugin-elevenlabs @livekit/agents-plugin-silero
If you have any questions or would like some examples to guide you further, please don’t hesitate to ask—I’m here to help! Sources: Docs::Agents | agents/src/voice/room_io/index.ts
r
import { voice } from '@livekit/agents'; this isnt exported so i wanted to know the new way you mentioned
t
It looks like the
voice
module might not be directly exported in the version of
@livekit/agents
you're using. Could you please share the exact version of the package you have installed? Also, are you running into any specific errors or challenges when trying to use the voice-related features? Knowing this will really help me guide you better and suggest the best possible solutions.
r
"@livekit/agents": "^0.7.9",
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!