Skip to main content

voicematic

A phone voice agent, assembled from independent parts: a telephony transport brings the call in (Genesys Cloud AudioHook out of the box), a voice engine hears and speaks, a brain with tools does the thinking, and call control hands the call back to the platform for a transfer. Each AI role picks its vendor: OpenAI, Anthropic and Mistral are built in, and for ears and mouth also ElevenLabs, Deepgram, Cartesia and Azure AI Speech; and any vendor that speaks the OpenAI or Anthropic protocol, or has a LangChain integration, is configuration.

pip install "voicematic[openai]"        # or [anthropic], [mistral], [elevenlabs], [deepgram], [cartesia], [azure], [langchain], [settings], [mcp], [genesys], [testing], [all]

The core is standard library only. Each vendor's SDK is an extra and loads only when that provider is used.

from fastapi import FastAPI, WebSocket

from voicematic import DUTCH, AgentProfile, VoiceAgent
from voicematic.telephony import StarletteWebSocket
from voicematic.telephony.genesys import AudioHookTransport
from voicematic.voice import EchoEngine

agent = VoiceAgent(
    AgentProfile(
        name="Voorbeeld",
        persona="Je bent de telefonische assistent van Voorbeeld BV.",
        instructions="Beantwoord vragen kort en eerlijk.",
        greeting="Goedendag, waarmee kan ik u helpen?",
        language=DUTCH,
    ),
    engine=EchoEngine,
)

app = FastAPI()


@app.websocket("/audiohook")
async def audiohook(ws: WebSocket) -> None:
    await ws.accept()
    await agent.handle(AudioHookTransport(StarletteWebSocket(ws), languages=[agent.profile.language.tag]))

EchoEngine needs no model: two tones, then the caller's own audio back. Swap it for a speech-to-speech engine (voicematic.providers.openai.GPTLiveEngine) or a PipelineEngine of ears, brain and mouth from any vendor.

Swappable components

Every part is an interface with built-in implementations. Your own subclass, or an adapter around a system you already have, slots in the same way:

Part Interface Built in Bring your own
Telephony TransportABC, CallControlABC Genesys AudioHook, Architect flow and Platform API transfers subclass
Voice engine VoiceEngineABC PipelineEngine, GPT-Live, gpt-realtime, EchoEngine subclass, or adapters.voicebot for an existing voice bot
Turn detection TurnDetectorABC EnergyTurnDetector subclass (a VAD, a semantic end-of-turn model)
Brain ReasonerABC ToolLoopReasoner, CallableReasoner subclass, an async function, or adapters.langchain for an existing agent
Chat model ChatModelABC OpenAI, OpenAI-compatible, Anthropic, Mistral; LangChain as the fallback for any other vendor subclass, or adapters.langchain for any LangChain model
Ears, mouth SpeechToTextABC, TextToSpeechABC OpenAI, Mistral, ElevenLabs, Deepgram, Cartesia, Azure subclass
Tools Tool, ToolRegistry MCP, the transfer tool a Tool, or LangChain tools via from_langchain_tools
Prompts PromptsABC DefaultPrompts subclass

A LangChain agent you already have, with its own tools and memory, as the brain:

from langgraph.prebuilt import create_react_agent

from voicematic import VoiceAgent
from voicematic.adapters.langchain import LangChainAgentReasoner

brain = LangChainAgentReasoner(
    # Called once per call with that call's tools, the transfer tool included.
    lambda tools: create_react_agent(model, [*my_tools, *tools], checkpointer=memory),
    history="latest",  # the agent remembers the call itself, keyed by the call id
    stream=True,       # speak sentence by sentence as the agent writes
)
agent = VoiceAgent.pipeline(profile, stt=ears, brain=brain, tts=mouth)

Just a LangChain model, with voicematic's prompt, tools and tool loop: brain=LangChainChatModel(ChatAnthropic(...)).

A voice bot you already have, behind the telephony (pacing, format conversion, transfers, hand-back timing, drain on deploy):

import websockets

from voicematic import VoiceAgent
from voicematic.adapters.voicebot import JsonBotProtocol, VoiceBotEngine, WebSocketVoiceBot


async def connect(session):
    return await websockets.connect("wss://bot.example.com/call")


agent = VoiceAgent(profile, engine=VoiceBotEngine.factory(lambda: WebSocketVoiceBot(connect, JsonBotProtocol())))

A bot with a wire protocol of its own subclasses BotProtocolABC, and one that is not a websocket implements VoiceBotABC. The bot reaches the agent's tools, the transfer tool included, through tool-call events.

Packages

Package What it holds
voicematic VoiceAgent (.pipeline, .echo), CallSession, AgentProfile, Tool, drain_on_signals
voicematic.telephony TransportABC, CallControlABC; genesys/ for AudioHook, Architect flow and Platform API transfers
voicematic.voice VoiceEngineABC, PipelineEngine, EchoEngine, TurnDetectorABC, EnergyTurnDetector, TurnHints
voicematic.reasoning ReasonerABC, ToolLoopReasoner, CallableReasoner, as_reasoner
voicematic.llm / speech ChatModelABC, SpeechToTextABC, TextToSpeechABC and the neutral conversation types
voicematic.providers the PROVIDERS registry; openai/, anthropic/, mistral/, elevenlabs/, deepgram/, cartesia/, azure/, and langchain as the fallback brain
voicematic.adapters existing systems: langchain/ (models, agents, tools), voicebot/ (a voice bot of your own)
voicematic.tools tool registry, parallel tool calls, the transfer tool, MCP
voicematic.prompts AgentProfile, Language, PromptsABC, DefaultPrompts
voicematic.audio formats, G.711, resampling, WAV
voicematic.settings VoicematicSettings: the voice layer from environment variables (extra)
voicematic.testing an AudioHook simulator (python -m voicematic.testing) and a browser test phone

Settings

voicematic[settings] adds VoicematicSettings, a pydantic BaseSettings with only what it takes to build the voice engine from the environment: VOICE_ENGINE, the vendor behind each role (REASONING_*, STT_*, TTS_*, VOICE_*), the vendor keys and pipeline turn-taking. It checks all of them at startup. A project subclasses it with its own settings:

from pydantic_settings import SettingsConfigDict

from voicematic import VoiceAgent
from voicematic.settings import VoicematicSettings


class Settings(VoicematicSettings):
    model_config = SettingsConfigDict(env_file=".env")
    audiohook_api_key: str | None = None


settings = Settings()
agent = VoiceAgent(profile, engine=settings.engine_factory())

The pipeline's turn-taking (PIPELINE_END_SILENCE, PIPELINE_FILLER_AFTER, PIPELINE_FILLER_ON=silence|lookup, PIPELINE_DETAILS_END_SILENCE, PIPELINE_ANSWER_GAP) comes from the environment; what only the project knows about its conversation goes in as code, settings.engine_factory(hints=TurnHints(...)): whether the agent's last reply asked for details callers give in parts (the next turn then waits PIPELINE_DETAILS_END_SILENCE), and whether what the caller said will certainly be looked up (the "one moment" line then plays at once).

Outside voicematic.settings, which the core never imports, the library reads no environment and knows no application: profile and tools come from the project. tests/test_boundary.py enforces that, and that each vendor SDK or framework is imported only in its own providers/<vendor>/ or adapters/<name>/.

A complete application, with settings, a Dutch profile, tools, MCP, transfers, Docker images and the full documentation, is in ../project.

Development

./test.sh                # ruff, mypy and pytest in .venv, with voicematic[dev] installed editable
./publish.sh             # the checks, a build, and an upload to PyPI (PYPI_API_KEY in .env)

Metadata

Release files for voicematic 0.4.0

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

Source distribution (sdist)

Source distribution for voicematic 0.4.0
File Size Uploaded Provenance Actions
voicematic-0.4.0.tar.gz 142.2 kB Without provenance Details for voicematic-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 273.7 kB

Release files / voicematic-0.4.0.tar.gz

Download URL voicematic-0.4.0.tar.gz
Size 142.2 kB
Tags Source
SHA-256 checksum
How to use checksums
358ef47683203819cf7792f4f5fbc88367afd20328cc46d52e069e704ea6c5f0
BLAKE2b-256 checksum
How to use checksums
6154c7f42e083e52794570b3cd36d22c47ab7eadefc5526c277d2ee74e9b2a8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / voicematic-0.4.0-py3-none-any.whl

Download URL voicematic-0.4.0-py3-none-any.whl
Size 131.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26caacfd3f24c1cd18f0a5eafc93fa605cd21662a81e4fba443e71c85fb4d684
BLAKE2b-256 checksum
How to use checksums
eb5c9f416a8aa37b9f40fc76a76b3c18bcbe5d6dbc53d8800e877d77d769121a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for voicematic 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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