Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 0a49fad

Browse files
authored
Merge pull request #20 from livekit-examples/use-turn-detector
enable turn-detector by default
2 parents 753590a + 54a5dca commit 0a49fad

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ LIVEKIT_API_KEY=<your API Key>
33
LIVEKIT_API_SECRET=<your API Secret>
44
OPENAI_API_KEY=<To use other providers, press Enter for now and edit .env.local>
55
DEEPGRAM_API_KEY=<To use other providers, press Enter for now and edit .env.local>
6+
CARTESIA_API_KEY=<To use other providers, press Enter for now and edit .env.local>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cd voice-pipeline-agent-python
2525
python3 -m venv venv
2626
source venv/bin/activate
2727
pip install -r requirements.txt
28+
python3 agent.py download-files
2829
```
2930

3031
Set up the environment by copying `.env.example` to `.env.local` and filling in the required values:
@@ -33,6 +34,7 @@ Set up the environment by copying `.env.example` to `.env.local` and filling in
3334
- `LIVEKIT_API_KEY`
3435
- `LIVEKIT_API_SECRET`
3536
- `OPENAI_API_KEY`
37+
- `CARTESIA_API_KEY`
3638
- `DEEPGRAM_API_KEY`
3739

3840
You can also do this automatically using the LiveKit CLI:

agent.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
WorkerOptions,
99
cli,
1010
llm,
11+
metrics,
1112
)
1213
from livekit.agents.pipeline import VoicePipelineAgent
13-
from livekit.plugins import openai, deepgram, silero
14+
from livekit.plugins import cartesia, openai, deepgram, silero, turn_detector
1415

1516

1617
load_dotenv(dotenv_path=".env.local")
@@ -38,18 +39,30 @@ async def entrypoint(ctx: JobContext):
3839
participant = await ctx.wait_for_participant()
3940
logger.info(f"starting voice assistant for participant {participant.identity}")
4041

41-
# This project is configured to use Deepgram STT, OpenAI LLM and TTS plugins
42-
# Other great providers exist like Cartesia and ElevenLabs
42+
# This project is configured to use Deepgram STT, OpenAI LLM and Cartesia TTS plugins
43+
# Other great providers exist like Cerebras, ElevenLabs, Groq, Play.ht, Rime, and more
4344
# Learn more and pick the best one for your app:
4445
# https://docs.livekit.io/agents/plugins
4546
agent = VoicePipelineAgent(
4647
vad=ctx.proc.userdata["vad"],
4748
stt=deepgram.STT(),
4849
llm=openai.LLM(model="gpt-4o-mini"),
49-
tts=openai.TTS(),
50+
tts=cartesia.TTS(),
51+
turn_detector=turn_detector.EOUModel(),
52+
# minimum delay for endpointing, used when turn detector believes the user is done with their turn
53+
min_endpointing_delay=0.5,
54+
# maximum delay for endpointing, used when turn detector does not believe the user is done with their turn
55+
max_endpointing_delay=5.0,
5056
chat_ctx=initial_ctx,
5157
)
5258

59+
usage_collector = metrics.UsageCollector()
60+
61+
@agent.on("metrics_collected")
62+
def on_metrics_collected(agent_metrics: metrics.AgentMetrics):
63+
metrics.log_metrics(agent_metrics)
64+
usage_collector.collect(agent_metrics)
65+
5366
agent.start(ctx.room, participant)
5467

5568
# The agent should be polite and greet the user when it joins :)

requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
livekit-agents>=0.12.1
2-
livekit-plugins-openai>=0.10.9
3-
livekit-plugins-deepgram>=0.6.13
1+
livekit-agents>=0.12.11
2+
livekit-plugins-openai>=0.10.17
3+
livekit-plugins-cartesia>=0.4.7
4+
livekit-plugins-deepgram>=0.6.17
45
livekit-plugins-silero>=0.7.4
6+
livekit-plugins-turn-detector>=0.4.0
57
python-dotenv~=1.0

taskfile.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ tasks:
1414
- platforms: [windows]
1515
cmd: echo -e "\tpowershell venv/Scripts/Activate.ps1\r"
1616
- echo -e "\tpip install -r requirements.txt\r"
17+
- echo -e "\tpython3 agent.py download-files\r"
1718
- echo -e "\tpython3 agent.py dev\r\n"
1819

1920
install:

0 commit comments

Comments
 (0)