Metadata-Version: 2.4
Name: openvoicechat
Version: 0.4.1
Summary: A small local voice runtime for Python: Parakeet STT, Kokoro TTS, and Silero VAD.
Author-email: Finity Alpha <fakhir.ali@finityalpha.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/fakhirali/OpenVoiceChat
Project-URL: Issues, https://github.com/fakhirali/OpenVoiceChat/issues
Keywords: voice,speech,stt,tts,parakeet,kokoro,local,telephony
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Requires-Dist: onnxruntime-gpu>=1.18; platform_system == "Linux" and platform_machine == "x86_64"
Requires-Dist: onnxruntime-gpu>=1.18; platform_system == "Windows" and platform_machine == "AMD64"
Requires-Dist: onnxruntime>=1.18; platform_system == "Darwin"
Requires-Dist: onnxruntime>=1.18; platform_system == "Linux" and platform_machine != "x86_64"
Requires-Dist: onnxruntime>=1.18; platform_system == "Windows" and platform_machine != "AMD64"
Requires-Dist: openai>=1.40
Requires-Dist: pysbd>=0.3.4
Requires-Dist: python-dotenv>=1.0
Requires-Dist: soxr>=0.4
Provides-Extra: local
Requires-Dist: sounddevice>=0.5; extra == "local"
Provides-Extra: models
Requires-Dist: torch>=2.4; extra == "models"
Requires-Dist: kokoro>=0.9.2; extra == "models"
Requires-Dist: soundfile>=0.12; extra == "models"
Requires-Dist: onnx-asr[hub]>=0.12; extra == "models"
Provides-Extra: twilio
Requires-Dist: fastapi>=0.110; extra == "twilio"
Requires-Dist: uvicorn[standard]>=0.29; extra == "twilio"
Requires-Dist: websockets>=12; extra == "twilio"
Provides-Extra: daily
Requires-Dist: daily-python>=0.14; extra == "daily"
Requires-Dist: fastapi>=0.110; extra == "daily"
Requires-Dist: uvicorn[standard]>=0.29; extra == "daily"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# 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.0, alpha.** The local pipeline, mic loop, and `ovc doctor` work.
> The shared multi-call runtime, Twilio/Daily transports, and `ovc init/run/bench`
> are the next steps. See [Roadmap](#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

```text
microphone ──► resample to 16 kHz ──► Conversation.input
                                           │
                                    Silero VAD + endpointing
                                           │ utterance PCM16
                                           ▼
                                   Parakeet (local STT)
                                           │ text
                                           ▼
                              OpenAI-compatible LLM (stream)
                                           │ sentences
                                           ▼
                                    Kokoro (local TTS)
                                           │ 16 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.

```bash
pip install "openvoicechat[local,models]"
cp .env.example .env      # then set LLM_API_KEY
```

```python
# voice.py — talk through the microphone and speakers
import asyncio

from openvoicechat import Config, Conversation
from openvoicechat.audio import run_local
from openvoicechat.local_speech import LocalSpeech


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


asyncio.run(main())
```

```bash
python voice.py
```

From a checkout, `python main.py --verbose` runs the same loop and exposes
`--model`, `--base-url`, `--voice`, and device flags. The `ovc` CLI currently
provides `ovc doctor`; `init`, `run`, `bench`, and `serve` land next.

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. Audio is
resampled between the device rate and 16 kHz internally. **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, resampled to 16 kHz for 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`, see the
[Kokoro voice list](https://huggingface.co/hexgrad/Kokoro-82M/blob/main/VOICES.md)).

### 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:

```dotenv
LLM_API_KEY=...
AGENT_API_TOKEN=...
DAILY_API_KEY=...
```

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

```python
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`, and `--voice`; 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:

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

or in code:

```python
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.

## Check your machine

```bash
ovc doctor
ovc doctor --json
```

`doctor` checks Python, `torch`/CUDA, ONNX Runtime providers, Parakeet and Kokoro
imports, audio devices, the Silero cache, and LLM configuration. It exits `0`
when ready and `2` when something required is missing. `--json` emits a stable
schema for agents:

```json
{
  "schema_version": 1,
  "ok": true,
  "checks": [{"name": "onnxruntime", "status": "ok", "detail": "1.31.1 | CUDAExecutionProvider"}]
}
```

## Turn taking

| Config field | Default | Effect |
|---|---:|---|
| `endpoint_silence_ms` | `600` | Silence before an utterance is sent to STT |
| `pre_roll_ms` | `300` | Audio kept before speech onset |
| `vad_threshold` | `0.6` | Silero speech probability threshold |
| `min_speech_ms` | `250` | 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 |

`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)`.

## Daily (optional)

The Daily transport lives in `openvoicechat/daily_agent/`. It is a thin call client,
but it still starts **one process per meeting**, so each meeting loads its own
models. Moving it onto a shared runtime is the next milestone.

```bash
pip install -e ".[daily,models]"
python scripts/daily_test.py --open
```

The script creates a room, starts the agent server, joins the agent, tails the
transcript, and cleans up on `Ctrl-C`.

Server:

```bash
uvicorn openvoicechat.daily_agent.server:app --host 0.0.0.0 --port 8001
```

`GET /health` is public; all other routes require
`Authorization: Bearer $AGENT_API_TOKEN`. `POST /join_meeting` takes
`meeting_url`, `prompt`, and `conversation_id`.

## Tests

```bash
pytest -q
ruff check .
```

Tests use fake providers and no network or GPU.

## Roadmap

| Milestone | Content |
|---|---|
| **0.4** | Local-only core, `ovc doctor`, 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** | Shared-runtime Daily transport, `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.
