Skip to content

codingjoe/VoIP

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:alice@sip.example.com transcribe

A simple echo server can be started with:

```console
SIP_PASSWORD=******** uvx 'voip[cli]' sip sips:alice@sip.example.com echo

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

SIP_PASSWORD=******** uvx 'voip[cli]' sip sips:alice@sip.example.com agent

Python API

uv add voip[audio,ai,pygments]

Subclass WhisperCall 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:alice@example.com",
            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.

About

Python VoIP library of the AI age

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Languages