Skip to content
openprxPublic

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

PRX Voice Engine

A real-time voice conversation orchestration engine built in Rust. PRX Voice manages the full lifecycle of AI-powered voice sessions — from speech recognition to agent reasoning to speech synthesis — with enterprise-grade observability, multi-tenancy, and compliance built in.

Architecture

┌─────────────────────────────────────────────────────┐
│                   prx-voice-bin                     │  ← Entry point
├─────────────────────────────────────────────────────┤
│              prx-voice-control                      │  ← REST / gRPC / WebSocket API
│         (auth, jwt, ratelimit, routing)              │
├──────────────┬──────────────┬───────────────────────┤
│  session     │   adapter    │   transport           │
│ (orchestrator│ (asr, tts,   │  (websocket,          │
│  manager,    │  agent, vad, │   media channel)      │
│  handoff,    │  fallback)   │                       │
│  recording)  │              │                       │
├──────────────┴──────────────┴───────────────────────┤
│   state (FSM)  │  event (bus, envelope, replay)     │
├────────────────┴────────────────────────────────────┤
│  policy    │  billing   │  audit     │  observe     │
│ (rbac,     │ (ledger,   │ (record,   │ (metrics,    │
│  tenant,   │  meter,    │  store,    │  slo,        │
│  quota)    │  pricing)  │  compliance│  degradation)│
├─────────────────────────────────────────────────────┤
│  storage (postgres, memory, object, migrations)     │
├─────────────────────────────────────────────────────┤
│  core (settings, flags, security, deploy)           │
├─────────────────────────────────────────────────────┤
│  types (ids, error, redact)                         │  ← Zero-dependency leaf
└─────────────────────────────────────────────────────┘

Crate Overview

Crate Purpose
prx-voice-types Shared IDs, error codes, enums. Zero external dependencies — leaf crate for the entire workspace.
prx-voice-state 12-state session FSM (Idle → Listening → UserSpeaking → AsrProcessing → Thinking → Speaking → …) with transition rules and interrupt semantics.
prx-voice-event CloudEvents v1.0 event system with bus, envelope, payload definitions, and event replay.
prx-voice-adapter Trait-based adapter interfaces for ASR, TTS, Agent, and VAD. Ships with mock, Deepgram, Azure, OpenAI, and local Sherpa/Ollama implementations.
prx-voice-session Session orchestrator coordinating state machine, adapters, event emission, turn management, handoff, and recording.
prx-voice-transport WebSocket and media channel abstraction.
prx-voice-control HTTP/gRPC control plane — REST API, JWT authentication, rate limiting.
prx-voice-policy Multi-tenant isolation, RBAC permission model, quota enforcement.
prx-voice-billing Usage metering, ledger, and pricing engine.
prx-voice-audit Audit logging, compliance checks, and audit record storage.
prx-voice-observe Prometheus metrics, SLO monitoring, 4-level degradation strategy, incident management.
prx-voice-storage PostgreSQL, in-memory, and object storage backends with migration support.
prx-voice-core Global configuration, feature flags, security settings, deployment config.
prx-voice-bin Server binary entry point with graceful shutdown.

Getting Started

Prerequisites

  • Rust 1.85+ (Edition 2024)
  • PostgreSQL 15+ (optional, in-memory store available for development)

Build

cargo build --workspace

Run

# With default config (mock adapters, in-memory store)
cargo run -p prx-voice-bin

# With custom config
PRX_VOICE_HOST=0.0.0.0 PRX_VOICE_PORT=3000 cargo run -p prx-voice-bin

# Override specific settings via environment variables
PRX_VOICE_SERVER__PORT=8080 cargo run -p prx-voice-bin

The server starts on http://localhost:3000 by default.

Running the real voice path locally

The realtime stream handlers (/api/v1/sessions/{id}/stream, /api/v1/stream) call local model services over HTTP. Start them in this order, each in its own terminal, from the repository root (the default model paths are relative to it).

# 0. One-time setup: Python packages and models (about 270 MB of downloads)
python3 -m venv models/.venv
models/.venv/bin/pip install -r models/requirements.txt   # pins sherpa-onnx<2, see the note below
bash models/download.sh

# 1. ASR server, port 8765 (zh streaming zipformer)
models/.venv/bin/python -u models/asr_server.py

# 2. zh TTS server, port 8766 (VITS theresa)
models/.venv/bin/python -u models/tts_server.py

# 3. en TTS server, port 8767 (Piper lessac); used in translate mode
models/.venv/bin/python -u models/tts_server_en.py

# 4. Any OpenAI-compatible LLM server (POST /v1/chat/completions), port 8080 by default.
#    Default example: llama.cpp llama-server with Qwen3.5-9B (Q4_K_M, 5.68 GB, Apache-2.0).
#    The first start downloads the model into the llama.cpp cache.
llama-server -hf unsloth/Qwen3.5-9B-GGUF:Q4_K_M --no-mmproj \
  --chat-template-kwargs '{"enable_thinking":false}' -c 8192 -ngl 99 --port 8080

# 5. The prx-voice binary, port 3000 by default
cargo run -p prx-voice-bin

The assistant keeps per-session conversation history (in memory, dropped when the session closes) and sends it to the LLM with every turn. It is bounded to the last 12 exchanges and about 4000 characters, oldest first; an interrupted reply is kept as far as it was produced, a failed turn is not kept, and translate mode never uses history.

Notes:

  • python -u keeps the server logs unbuffered, so they are visible when output is redirected to a file. Run every command from the repository root; the default model paths are relative.
  • models/requirements.txt pins sherpa-onnx<2: sherpa-onnx 2.x removed the built-in espeak-ng phonemizer, so the English Piper voice cannot synthesize any text with it.
  • Qwen3.5 thinks by default; enable_thinking:false turns that off, which a voice reply needs (otherwise the first audio waits for the whole thinking phase). --no-mmproj skips the vision projector, which the voice path does not use. The model is unsloth/Qwen3.5-9B-GGUF, file Qwen3.5-9B-Q4_K_M.gguf (a GGUF conversion of Apache-2.0 Qwen/Qwen3.5-9B); expect roughly 7-8 GB of memory with the 8192-token context. Any other OpenAI-compatible server works too: point LLM_BASE_URL at it (add LLM_MODEL / LLM_API_KEY if it needs them). Ollama keeps working through LLM_BASE_URL=http://localhost:11434 and LLM_MODEL=<pulled model>.

The binary resolves these service addresses once at first use; the defaults apply when a variable is unset:

Variable Default Used for
ASR_URL http://localhost:8765 ASR server (POST /asr)
LLM_BASE_URL http://localhost:8080 OpenAI-compatible LLM server (POST {base}/v1/chat/completions, streamed)
LLM_MODEL qwen2.5:1.5b Model name sent in the request (llama-server ignores it; Ollama needs a pulled model)
LLM_API_KEY unset Sent as Authorization: Bearer ... only when set and non-empty (hosted endpoints)
OLLAMA_URL / OLLAMA_MODEL unset Deprecated fallbacks for LLM_BASE_URL / LLM_MODEL, used only when the new variable is unset
TTS_URL http://localhost:8766 zh TTS server (POST /tts)
TTS_EN_URL http://localhost:8767 en TTS server (translate mode)
TTS_CLONE_URL http://localhost:8768 voice clone TTS server (clone mode)
PRX_VOICE_HOST / PRX_VOICE_PORT 0.0.0.0 / 3000 listen address of the binary

The Python servers read ASR_PORT, TTS_PORT, TTS_EN_PORT, ASR_MODEL_DIR, TTS_MODEL_DIR and TTS_EN_MODEL_DIR (defaults: ports 8765/8766/8767 and the directories fetched by models/download.sh).

Acceptance check: send a 16 kHz mono PCM16 WAV recording through the stream WebSocket. The client creates a session, streams the audio, sends audio_end and prints every text message (transcript, token, response, ...) and the byte count of each binary TTS frame:

cargo run -p prx-voice-adapter --example ws_voice_client -- recording.wav --base-url http://127.0.0.1:3000

Docker

# Build and run
docker compose up --build

# Or build image directly
docker build -t prx-voice .
docker run -p 3000:3000 prx-voice

Test

# Run all tests
cargo test --workspace

# Run specific crate tests
cargo test -p prx-voice-state
cargo test -p prx-voice-session

# Integration tests
cargo test -p prx-voice-integration-tests

Configuration

Configuration is loaded from config.yaml and can be overridden via environment variables with the PRX_VOICE_ prefix:

server:
  host: "0.0.0.0"
  port: 3000

session:
  max_duration_sec: 1800
  max_turns: 100
  interrupt_enabled: true
  default_language: "en-US"

adapters:
  default_asr_provider: "mock"     # mock | deepgram | local
  default_agent_provider: "mock"   # mock | openai | local
  default_tts_provider: "mock"     # mock | azure | local

Adapter Providers

Component Provider Description
ASR mock Returns canned transcriptions for testing
ASR deepgram Deepgram streaming ASR (DEEPGRAM_API_KEY)
ASR local Sherpa-ONNX offline ASR
Agent mock Echo agent for testing
Agent openai OpenAI GPT models (OPENAI_API_KEY)
Agent local Ollama local LLM (adapter layer; the realtime stream path uses LLM_BASE_URL instead)
TTS mock Returns silence for testing
TTS azure Azure Cognitive Services TTS (AZURE_SPEECH_KEY, AZURE_SPEECH_REGION)
TTS local Sherpa-ONNX offline TTS

API

REST Endpoints

POST   /api/v1/sessions              Create a new voice session
GET    /api/v1/sessions/:id          Get session details
POST   /api/v1/sessions/:id/close    Close a session
POST   /api/v1/sessions/:id/interrupt Interrupt current playback
GET    /api/v1/sessions/:id/events   Event stream (WebSocket)
GET    /api/v1/health/live           Liveness probe
GET    /api/v1/health/ready          Readiness probe
GET    /api/v1/metrics               Prometheus metrics

WebSocket

GET    /api/v1/sessions/:id/stream   Full-duplex audio + events (PCM16 16 kHz in, PCM16 16 kHz out)
GET    /api/v1/stream                Unified multi-session stream

All REST responses use a unified envelope:

{
  "request_id": "uuid",
  "timestamp": "2024-01-01T00:00:00Z",
  "data": { ... },
  "error": null
}

Deployment

Kubernetes (Helm)

helm install prx-voice deploy/helm/prx-voice \
  -f deploy/helm/values-us-east.yaml

Region-specific value files are provided for us-east, us-west, and eu-west.

Project Status

This project is in alpha. The core session lifecycle, state machine, event system, and adapter framework are functional. Enterprise features (billing, audit, RBAC) are structurally complete but not yet production-hardened.

License

MIT License — see LICENSE for details.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages