Skip to main content

Python asyncio library for VoIP calls.

Project description

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.

Sponsors

Sponsors

Usage

To get started, you will need a SIP account. One is usually included with ISP. Check your ISP's documentation or router for details.

You will need a SIP AOR (URI), which looks like this:

sip:USER:PASSWORD@SIP_SERVER;transport=TCP

[!NOTE] This library uses secure defaults (TLS transport on port 5061). However, most SIP servers only support unencrypted connections. Therefore, you will need to provide an explict transport parameter.

CLI

A simple echo call can be started with:

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

Each command supports an optional --dial argument to initiate an outbound call instead of waiting for an inbound one.

To dial a number, say a message, and hang up automatically:

uvx 'voip[cli]' sip sips:alice:********@sip.example.com say sip:+15551234567@sip.example.com "Your package has arrived."

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

uvx 'voip[cli]' sip sips:alice:********@sip.example.com agent --initial-prompt "Hi, I am looking for a Mr. Ron, first name Mo?"

MCP

The voip package ships a ready-made Model Context Protocol (MCP) server that exposes tools to make phone calls on your behalf to any MCP client.

{
  "mcpServers": {
    "VoIP": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "voip[mcp]",
        "mcp"
      ],
      "env": {
        "SIP_AOR": "sip:****:****@example.com:5060?transport=tcp"
      }
    }
  }
}

Python API

uv add voip[audio,ai,pygments]

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

import asyncio
import dataclasses
import ssl
from voip.ai import TranscribeCall
from voip.sip.protocol import SIP
from voip.sip.types import SipURI
from voip.sip.transactions import InviteTransaction
from voip.rtp import RealtimeTransportProtocol
from faster_whisper import WhisperModel


@dataclasses.dataclass(kw_only=True, slots=True)
class TranscribingCall(TranscribeCall):
    def transcription_received(self, text) -> None:
        print(text)


class TranscribeInviteTransaction(InviteTransaction):
    def invite_received(self, request) -> None:
        self.ringing()
        self.answer(
            session_class=TranscribingCall,
            stt_model=WhisperModel("kyutai/stt-1b-en_fr-trfs", device="cuda"),
        )


async def main():
    loop = asyncio.get_running_loop()
    _, rtp_protocol = await loop.create_datagram_endpoint(
        RealtimeTransportProtocol,
        local_addr=("0.0.0.0", 0),
    )
    ssl_context = ssl.create_default_context()
    await loop.create_connection(
        lambda: SIP(
            rtp=rtp_protocol,
            aor=SipURI.parse("sips:alice:********@example.com"),
            transaction_class=TranscribeInviteTransaction,
        ),
        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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

voip-0.5.2.tar.gz (62.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

voip-0.5.2-py3-none-any.whl (74.7 kB view details)

Uploaded Python 3

File details

Details for the file voip-0.5.2.tar.gz.

File metadata

  • Download URL: voip-0.5.2.tar.gz
  • Upload date:
  • Size: 62.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for voip-0.5.2.tar.gz
Algorithm Hash digest
SHA256 d52c811d84d1f93cdb8642b765ddbb7bee7604e0b687a7933f28a27dc9148efe
MD5 2aabc9513002befd5dd99ae52e8d25e2
BLAKE2b-256 2ad406e232ce3eea15fa30f64deb91ebdc51633de37af1879aa6dd52d25f8c51

See more details on using hashes here.

Provenance

The following attestation bundles were made for voip-0.5.2.tar.gz:

Publisher: release.yml on codingjoe/VoIP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file voip-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: voip-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 74.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for voip-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce29186e575defc2ad38210b0f94bb31945b91add2502fac467058908652fb9d
MD5 39396ddea21d5264a1854b068b5917d2
BLAKE2b-256 664c31d06ec7724490d1ea73fee33bbc05ae6afca9f542f878a7fba895d0fc61

See more details on using hashes here.

Provenance

The following attestation bundles were made for voip-0.5.2-py3-none-any.whl:

Publisher: release.yml on codingjoe/VoIP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page