Skip to content
项目

关于

Have a natural voice conversation with an LLM

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

OpenVoiceChat

The local voice runtime for Python. Parakeet STT, Kokoro TTS, Silero VAD — one GPU, many calls, no cloud voice APIs, no provider zoo, no platform.

Status: 0.4.1, alpha. The local pipeline and the mic loop work. The shared multi-call runtime and the Twilio transport are the next steps. See Roadmap.

What it is

A small library for embedding an interruptible voice agent in a Python process:

  • STT: NVIDIA Parakeet TDT 0.6B v3 via onnx-asr (ONNX Runtime)
  • TTS: Kokoro-82M
  • VAD / endpointing: Silero VAD v5
  • LLM: any OpenAI-compatible API; Config(llm_base_url=..., llm_model=...) points at OpenAI, Ollama, llama.cpp, vLLM, or your own gateway

It is not a platform, a model zoo, or a cloud speech wrapper. There is no dashboard, auth service, database, or provider registry.

Architecture

microphone ──► resample to 16 kHz ──► Conversation.input
                                           │
                                    Silero VAD + endpointing
                                           │ utterance PCM16
                                           ▼
                                   Parakeet (local STT)
                                           │ text
                                           ▼
                              OpenAI-compatible LLM (stream)
                                           │ sentences
                                           ▼
                                    Kokoro (local TTS)
                                           │ 24 kHz PCM16
                                           ▼
speaker ◄── resample to device rate ◄── Conversation.output

Conversation is the whole engine: endpointing, barge-in, sentence-level TTS, and history. Transports only move PCM16 in and out.

Quickstart

Python 3.11+ is required.

pip install "openvoicechat[local,models]"
cp .env.example .env      # then set LLM_API_KEY
# voice.py — talk through the microphone and speakers
import asyncio

from openvoicechat import Config, Conversation
from openvoicechat.audio import run_local
from openvoicechat.stt import LocalSTT
from openvoicechat.tts import LocalTTS


async def main() -> None:
    conversation = Conversation(
        LocalSTT(),
        LocalTTS(),
        config=Config(),
        on_turn=lambda role, text: print(f"{role.upper()}: {text}"),
    )
    await run_local(conversation)


asyncio.run(main())
python voice.py

From a checkout, python main.py --verbose runs the same loop and exposes --model, --base-url, --voice, --speed, --reasoning-effort, and device flags.

The first run downloads Parakeet (~2 GB), Kokoro-82M (~330 MB), and Silero VAD (~2 MB). --verbose prints speech start/end, endpointing, STT, LLM first-token, and TTS timings. Ctrl-C stops it.

On Linux you may need PortAudio: sudo apt install libportaudio2.

--prompt, --input-device, and --output-device are available. The mic is resampled to the 16 kHz STT/VAD rate; Kokoro output stays at 24 kHz and is resampled once, to the device rate. Use headphones — there is no echo cancellation, and speaker output will feed back into the VAD.

Models and hardware

Component Model Notes
STT nvidia/parakeet-tdt-0.6b-v3 ONNX Runtime; CUDA where available, CPU otherwise
TTS hexgrad/Kokoro-82M 24 kHz native, kept at 24 kHz through the pipeline
VAD Silero VAD v5 Always CPU, ~0.4% of one core

On Linux x86_64 and Windows AMD64 the core dependency is onnxruntime-gpu, so Parakeet uses CUDA when present and falls back to CPU. macOS and non-x86 Linux use the CPU onnxruntime build. Kokoro uses CUDA when torch reports it.

Measured on one RTX 3080 Ti (12 GB), Python 3.12:

Metric Value
Model load (Parakeet + Kokoro) ~6.9 s
Kokoro warm RTF ~0.01
Parakeet steady transcription ~0.019 s per utterance
Peak VRAM ~5.2 GB

These are single-session numbers. Concurrent-call benchmarks are not published yet; that measurement is part of the next milestone.

Pick a voice with --voice (default af_heart, the top-graded American voice; af_bella is the expressive A- alternative) and a pace with --speed (default 1.2; 1.0 is Kokoro's natural pace, 1.3 is brisk, above 1.5 starts to clip). See the Kokoro voice list.

Startup warnings

Startup prints one ONNX Runtime CUDA memcpy notice and three torch deprecation warnings from Kokoro. They are expected and do not affect output:

  • Kokoro runs in eval() mode and its dropout calls pass training=False.
  • The dropout warning is PyTorch noting an unused dropout argument on a single-layer LSTM, where dropout is ignored by definition.
  • The other two are genuine deprecations inside Kokoro's model code; they will disappear when Kokoro updates.

They print once per process. The library does not hide them.

Configuration

.env holds secrets only:

LLM_API_KEY=...

Everything else is a field on Config in openvoicechat/config.py:

from openvoicechat import Config

config = Config(
    llm_model="gpt-6-luna",
    llm_base_url="",           # empty means https://api.openai.com/v1
    endpoint_silence_ms=400,
    vad_threshold=0.6,
)

main.py exposes --model, --base-url, --voice, --speed, --reasoning-effort, --service-tier, and --no-warmup; edit Config for everything else. Nothing besides secrets is read from the environment.

LLM

The default is OpenAI with gpt-6-luna. Point it elsewhere with flags:

python main.py --base-url http://localhost:11434/v1 --model qwen3:4b

or in code:

config = Config(llm_base_url="http://localhost:8000/v1", llm_model="my-model")

llama.cpp (http://localhost:8080/v1) and vLLM (http://localhost:8000/v1) work the same way. llm_timeout_s defaults to 15 seconds with one retry, so a stalled model cannot freeze a turn.

Turn taking

Config field Default Effect
endpoint_silence_ms 96 Silence before an utterance is sent to STT
pre_roll_ms 320 Audio kept before speech onset
vad_threshold 0.6 Silero speech probability threshold
min_speech_ms 256 Utterances shorter than this are dropped
max_utterance_ms 30000 Rolling window for one uninterrupted utterance
output_chunk_ms 100 TTS chunk size written to the transport

Delays are counted in whole 32 ms frames, so the defaults sit on that grid and any other value rounds up to the next frame.

max_utterance_ms does not cut a speaker off mid-sentence. Past the cap the engine keeps the most recent window and waits for silence, so a long monologue costs bounded memory instead of cancelling its own turn.

Override any of these in code, for example Config(endpoint_silence_ms=400).

Latency

Conversation measures every turn from the last frame of user speech:

Field Meaning
endpoint_ms Last speech → endpoint decision (mostly endpoint_silence_ms)
stt_ms Parakeet transcription of the utterance
llm_ttft_ms LLM request → first streamed token
first_sentence_ms Last speech → first complete sentence handed to TTS
tts_first_ms First Kokoro synthesis
voice_to_voice_ms Last speech → first audio chunk queued
turn_ms Last speech → reply fully queued

completed is false when a barge-in or error cut the turn short, so filter those out before averaging.

voice_to_voice_ms is the headline number. main.py --verbose prints it after every turn:

[conversation] latency | v2v=1187ms endpoint=608ms stt=79ms llm_ttft=412ms sentence=731ms tts=88ms turn=1402ms

Read it from code with on_latency or conversation.last_latency:

from openvoicechat import Conversation, TurnLatency


def on_latency(latency: TurnLatency) -> None:
    print(f"voice to voice: {latency.voice_to_voice_ms:.0f} ms")


conversation = Conversation(stt, tts, config=Config(), on_latency=on_latency)

The queued number excludes the transport hop. For the real device time, have the transport report its first write; the local speaker already does:

await stream.write(first_frame)
conversation.audio_written()

That logs first audio written (…ms after last speech). It is not a true acoustic measurement — PortAudio buffers a little audio before it reaches the speaker — but it is the closest point the pipeline can observe.

Call logs and reports

--log writes a JSONL event stream with wall-clock timestamps:

python main.py --log calls/2026-11-26.jsonl
python scripts/visualize_call.py calls/2026-11-26.jsonl

Omit the path and the log gets a random id under logs/, which is gitignored:

python main.py --log
# Recording events to logs/20261126-233412-a1b2c3d4.jsonl

The report prints aggregate numbers, a mean latency breakdown with bars, and one row per turn with its metrics and transcript. It writes to stdout, so it pipes into less, head, or a file like any other command. --log is independent of --verbose.

scripts/visualize_call.py is a small stdlib-only script that lives in the repository, not the wheel.

From code, pass on_event and write the records wherever you like:

import json


def on_event(event: dict) -> None:
    with open("call.jsonl", "a", encoding="utf-8") as handle:
        handle.write(json.dumps(event) + "\n")


conversation = Conversation(stt, tts, config=Config(), on_event=on_event)

Every record has event and t (epoch seconds). The names are call_start, speech_start, endpoint, stt, llm_first_token, tts, first_audio_written, barge_in, dropped, turn_done, and call_end.

Tests

pytest -q
ruff check .

Tests use fake providers and no network or GPU.

Roadmap

Milestone Content
0.4 Local-only core, P1 turn-taking fixes
0.5 VoiceRuntime: load models once, serve many sessions; ovc init/run/bench
0.6 Twilio Media Streams transport and scaffold
0.7 ovc eval, concurrency benchmarks
1.0 Stable API, published comparisons, extension docs

Full browser STT + TTS is a separate later package, not part of the Python core.

License and attribution

Code is Apache-2.0. Model licenses are upstream: Parakeet is CC-BY-4.0, Kokoro is Apache-2.0, and Silero VAD is MIT. Check each model card before redistribution.

探索相关项目

加载中…