Skip to main content

myvoiceai

A reusable voice AI session package for real-time WebSocket voice pipelines.

Installation

Install the package from PyPI:

pip install myvoiceai

Install with optional observability support:

pip install myvoiceai[observability]

Quickstart

Use the run_voice_session() function to start a voice session. Pass API keys and session config as arguments (no required .env):

from myvoiceai import run_voice_session

await run_voice_session(
    websocket=client_websocket,
    system_prompt="You are a helpful assistant.",
    greeting_message="Hello! How can I help you today?",
    session_id="session-001",
    model="gemini-2.5-flash",
    llm_provider_api_key="your-gemini-key",
    deepgram_api_key="your-deepgram-key",
    tracing=False,
    endpointing=1200,
    utterance_end=2500,
    stable_interim_secs=1.5,
    stable_interim_secs_no_punct=3.0,
    inactivity_timeout_seconds=30,
)

Custom Tools

Pass only one tool (echo) with an OpenAI-style function schema:

from myvoiceai.tools import ToolRegistry

my_registry = ToolRegistry()

async def echo(**kwargs):
    return kwargs.get("text", "")

my_registry.register(
    name="echo",
    schema={
        "type": "function",
        "function": {
            "name": "echo",
            "description": "Echo back the text provided by the LLM.",
            "parameters": {
                "type": "object",
                "properties": {
                    "text": {"type": "string", "description": "Text to echo back"}
                },
                "required": ["text"],
            },
        },
    },
    impl=echo,
)

await run_voice_session(
    websocket=ws,
    tool_registry=my_registry,
    llm_provider_api_key="your-gemini-key",
    deepgram_api_key="your-deepgram-key",
)

Example Server

Run the FastAPI example server (keys passed via .env in the example, but they can also be hardcoded or passed through config):

uvicorn myvoiceai.example.fastapi_app:app --host 0.0.0.0 --port 8000

Connect WebSocket clients to ws://localhost:8000/ws/voice.

Key Configuration

Keys are passed directly to run_voice_session() or CustomVoiceAgent:

  • api_key — LLM provider API key (e.g., Gemini / OpenAI)
  • deepgram_api_key — Deepgram STT/TTS key
  • session_id — Session identifier for tracing/logging (replaces old interview_id)
  • model — Model identifier (e.g., gemini-2.5-flash)
  • tracing — True only if [observability] extras are installed; default False

A .env.example is included for local convenience but is optional.

API Reference

run_voice_session(websocket, ...)

Main entry point. Parameter reference:

Parameter Use / Purpose
websocket WebSocket connection from FastAPI / client
system_prompt LLM system instruction (default: concise voice assistant)
greeting_message First spoken message to user
session_id Session identifier for tracing/logs (replaces old interview_id)
model LLM model ID (e.g., gemini/gemini-2.5-flash)
llm_provider_api_key LLM provider API key (required)
deepgram_api_key Deepgram STT/TTS API key (required)
stt_model Deepgram STT model (default nova-2)
tts_model Deepgram TTS voice model (default aura-asteria-en)
tracing True only with [observability] installed; sends traces to OTLP
tool_registry ToolRegistry with custom function schemas
endpointing Pause duration (ms) after endpointing
utterance_end Stop recording (ms) when utterance ends
stable_interim_secs Stable interim result delay (secs)
stable_interim_secs_no_punct Same, when no punctuation detected
inactivity_timeout_seconds Close session after silence (default 10)
max_session_seconds Hard session time cap (CustomVoiceAgent only)

CustomVoiceAgent

Core pipeline class. Same params as run_voice_session plus client_websocket, max_session_seconds, max_duration_message, inactivity_message.

CustomVoiceAgent

Core pipeline class. Initialize with client_websocket and optional system_prompt, greeting_message, session_id, model, api_key, deepgram_api_key, tracing, tool_registry.

ToolRegistry

Dynamic registry for callable tools. Use .register() with full function schema, .lookup() to retrieve, .schemas() to get LLM-ready tool definitions.

Observability / Tracing

Install extras and run the local collector stack to enable tracing:

pip install myvoiceai[observability]

Example infrastructure files are included in example/:

  • docker-compose.yml — Jaeger (UI at localhost:16686) + OpenTelemetry Collector (4318/4319)
  • otel-collector-config.yaml — Collector pipeline: OTLP → batch → Jaeger + Prometheus metrics
  • prometheus.yml — Scrapes collector metrics at localhost:8889

Start the stack:

cd example
# Set OTLP endpoint in your app to http://localhost:4318 (HTTP) or localhost:4317 (gRPC)
docker-compose up -d

Then run the session with tracing enabled:

await run_voice_session(
    websocket=ws,
    tracing=True,
    session_id="session-001",
    api_key="...",
    deepgram_api_key="...",
)

Jaeger UI: http://localhost:16686 (search by session.id).

Browser compatibility: Tested on Chrome and Edge. Firefox may have playback issues due to client-side HTML5 audio/API differences (this is a browser-side issue, not the voice pipeline). Update index.html if needed for Firefox.

WebSocket Messages

Client must send {"control": "playback_complete"} via WebSocket when audio playback finishes so the server can reset is_ai_speaking and track inactivity correctly.

Browser compatibility: Tested on Chrome and Edge. Firefox may have playback issues due to client-side HTML5 audio/API differences (this is a browser-side issue, not the voice pipeline). Update index.html if needed for Firefox.

Server sends JSON over the WebSocket:

  • transcript_chunk — incremental partial transcript (role: user or assistant; turn_id; text; optional replace)
  • transcript — finalized transcript (role; text; turn_id)
  • turn — completed turn (turn_id; timestamp; user; assistant; interrupted: bool)

Client should listen for these to update UI/state.

Notes

  • The package does not include infrastructure files like docker-compose.yml or prometheus.yml. These are maintained separately.
  • Observability (OpenTelemetry) is optional via pip install myvoiceai[observability]. Without it, tracing=False runs normally.
  • .env is excluded from the package for security. Only .env.example ships for reference.
  • All tool schemas must use the OpenAI-style {"type": "function", "function": {...}} format.

Metadata

Release files for myvoiceai 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for myvoiceai 0.0.3
File Size Uploaded
myvoiceai-0.0.3.tar.gz 19.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for myvoiceai 0.0.3
File Interpreter ABI Platform
myvoiceai-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 36.3 kB

Release files / myvoiceai-0.0.3.tar.gz

Download URL myvoiceai-0.0.3.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2fc37f2d6c942c0b2f2a0d035937c8a199e02f34d8926d7ea79d0fea21e99b05
BLAKE2b-256 checksum
How to use checksums
472f8742754fc804633d3c178a946d320bc3df925eb9298bd48350076048b004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / myvoiceai-0.0.3-py3-none-any.whl

Download URL myvoiceai-0.0.3-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c242e852b97da2486b8e0916c71c323a57ec1659cc26cdfd444aaf98ec30b875
BLAKE2b-256 checksum
How to use checksums
fce08d230de1348c499b72cd2c680f4a66bd281e447a2265022826a6c72fb7e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page