Skip to content

Python VoIP
Documentation | Issues | Changelog | Funding

Python VoIP

Async VoIP Python library for the AI age.

Warning

This library is in early development and may contain breaking changes. Use with caution.

Usage

CLI

Answer calls and transcribe them live from the terminal:

SIP_PASSWORD=******** uvx 'voip[cli]' sip sips:[email protected] transcribe

A simple echo server can be started with:

```console
SIP_PASSWORD=******** uvx 'voip[cli]' sip sips:[email protected] echo

You can also talk to a local agent (needs Ollama):

SIP_PASSWORD=******** uvx 'voip[cli]' sip sips:[email protected] agent

Python API

uv add voip[audio,ai,pygments]

Subclass TranscribeCall and override transcription_received to handle results. Pass it as call_class when answering an incoming call:

import asyncio
import ssl
from voip.ai import TranscribeCall
from voip.sip.protocol import SIP


class MyCall(TranscribeCall):
    def transcription_received(self, text: str) -> None:
        print(f"[{self.caller}] {text}")


class MySession(SIP):
    def call_received(self, request) -> None:
        asyncio.create_task(self.answer(request=request, call_class=MyCall))


async def main():
    loop = asyncio.get_running_loop()
    ssl_context = ssl.create_default_context()
    await loop.create_connection(
        lambda: MySession(
            aor="sips:[email protected]",
            username="alice",
            password="secret",
        ),
        host="sip.example.com",
        port=5061,
        ssl=ssl_context,
    )
    await asyncio.Future()


asyncio.run(main())

For raw audio access without transcription, subclass AudioCall and override audio_received(self, audio: np.ndarray) instead.