Skip to main content

End of utterance detection for LiveKit Agents

Project description

LiveKit Turn Detection Plugin (Vietnamese)

A specialized turn detection plugin for LiveKit Agents, optimized for Vietnamese language contexts. This plugin uses a local ONNX model to predict the end of a user's turn with high accuracy and low latency.

Features

  • Vietnamese Optimized: Fine-tuned for Vietnamese conversational patterns.
  • Local Inference: Runs ONNX model locally for privacy and speed.
  • Context Aware: Considers preceding assistant messages for better prediction accuracy.
  • Lightweight: Uses SafeTensor / ONNX quantization for minimal memory footprint.

Development Workflow

flowchart TD
    Train[Train BERT Model] -->|Export| Export[Export to ONNX]
    Export -->|Copy & Replace| Replace[Replace livekit/plugins/turn_detection/model_quantized.onnx]
    Replace -->|Build| Build[Build Wheel .whl]
    Build -->|Push| Push[Push to S3 or PyPI]
    Push -->|Install via uv/pip| Install[Install in Target Project]

Build Instructions

You can build the package wheel using uv (recommended) or build.

Build Wheel

Run the build command in the project root:

uv build

This will create a .whl file in the dist/ directory (e.g., dist/livekit_plugins_turn_detection-1.0.0-py3-none-any.whl).

Installation

You can verify the build and install the generated wheel file directly into your environment:

pip install dist/livekit_plugins_turn_detection-1.0.0-py3-none-any.whl

Usage

Integrate the TurnDetectionModel into your LiveKit VoicePipelineAgent.

Basic Integration

from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import openai, silero
from livekit.plugins.turn_detection import TurnDetectionModel

class Assistant(Agent):
    def __init__(self) -> None:
        super().__init__()

async def entrypoint(ctx: JobContext):
    await ctx.connect()

    session = AgentSession(
        vad=silero.VAD.load(),
        stt=openai.STT(language="vi"),
        llm=openai.LLM(),
        tts=openai.TTS(),
        # Initialize the turn detector
        turn_detection=TurnDetectionModel(threshold=0.5),
    )

    await session.start(
        agent=Assistant(),
        room=ctx.room
    )

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

Configuration

The TurnDetectionModel accepts the following parameters:

  • threshold (float, default 0.5): Probability threshold (0.0 - 1.0) to trigger end-of-turn. Higher values reduce false interruptions but may increase latency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file livekit_plugins_turn_detection-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for livekit_plugins_turn_detection-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a6fb46c6ed3b14b3024e5d77f8c31bdaedd2922abff839590d5cf60516e7dd
MD5 c89a495f4bd6f0028aaa0c2cf13ff6e1
BLAKE2b-256 0e5dc97e4ca865407ca17de209df4d97fab6cc660761cdc7d444d700512c472a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page