Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

baresipy

A python wrapper around baresip, the portable SIP user-agent.

Use it to place and receive VoIP calls from python: dial out, answer inbound calls, stream text-to-speech or arbitrary audio into a call, send/receive DTMF, transcribe what a caller says, and build interactive voice bots — with or without a SIP registrar, with or without a sound card.

Install

sudo apt-get install baresip ffmpeg   # Debian/Ubuntu, see docs/setup.md for other distros
pip install baresipy

baresip is the SIP engine baresipy drives via pexpect; ffmpeg is used by pydub for audio conversion. See docs/setup.md for per-distro install commands, SIP account requirements, and troubleshooting.

Optional extras:

extra installs needed for
baresipy[ovos] ovos-plugin-manager, phoonnx, ovos-simple-listener speak()/say() default TTS engine, baresipy.ovos.BareSIPMicrophone, voice bots
baresipy[server] fastapi, uvicorn, python-multipart baresipy-gateway HTTP/WebSocket API, see docs/http-gateway.md
baresipy[test] pytest, pytest-cov, fastapi, httpx, python-multipart, uvicorn running the test suite

Quickstart

Scripted call

Dial a number, speak, hang up:

from baresipy import BareSIP
from time import sleep

b = BareSIP("your_user", "your_password", "your_sip_gateway.example")
b.call("someone@your_sip_gateway.example")

while b.running:
    sleep(0.5)
    if b.call_established:
        b.speak("hello, this is a test")
        b.hang()
        b.quit()
        break

Full runnable version: examples/scripted_call.py.

Answering bot

Subclass BareSIP and override the event handlers:

from baresipy import BareSIP
from time import sleep


class JokeBOT(BareSIP):
    def handle_incoming_call(self, number):
        self.accept_call()

    def handle_call_established(self):
        self.speak("Welcome to the jokes bot")
        self.speak("Goodbye")
        self.hang()


b = JokeBOT("your_user", "your_password", "your_sip_gateway.example")
while b.running:
    sleep(1)

Full runnable version: examples/events.py.

OVOS voice bot

Answer a call and transcribe the caller with an OVOS STT/VAD pipeline, using the incoming call audio as a microphone source:

from baresipy import BareSIP
from baresipy.ovos import BareSIPMicrophone
from ovos_plugin_manager.stt import OVOSSTTFactory
from ovos_plugin_manager.vad import OVOSVADFactory
from ovos_simple_listener import SimpleListener, ListenerCallbacks


class VoiceBot(BareSIP):
    def handle_incoming_call(self, number):
        self.accept_call()

    def handle_call_established(self):
        mic = BareSIPMicrophone(sip=self)
        SimpleListener(mic=mic, wakeword=None,
                        vad=OVOSVADFactory.create(),
                        stt=OVOSSTTFactory.create(),
                        callbacks=ListenerCallbacks()).start()


bot = VoiceBot("your_user", "your_password", "your_sip_gateway.example", record_rx=True)

Full runnable version with two-way TTS replies: examples/voice_bot.py. See docs/ovos-integration.md for the complete walkthrough.

Features

Feature How
Registered SIP account calls BareSIP(user, pwd, gateway)
Registrar-less direct SIP calls BareSIP() + call("sip:user@ip:5060"), see docs/direct-calls.md
Headless operation (no sound card) BareSIP(headless=True)
Text-to-speech into a call speak() via any OPM TTS plugin
Arbitrary audio into a call send_audio(path)
DTMF (send/receive) send_dtmf(digits, mode="keys"), handle_dtmf_received()
Recording inbound call audio record_rx=True, get_rx_wav() / get_rx_stream()
OVOS microphone plugin baresipy.ovos.BareSIPMicrophone
Local contact list baresipy.contacts.ContactList
Event-driven call handling override handle_* methods

Documentation

Credits

This work has been sponsored by Matt Keys, eZuce Inc

License

MIT

Download files

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

Source Distribution

baresipy-1.2.0a1.tar.gz (48.8 kB view details)

Uploaded Source

Built Distribution

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

baresipy-1.2.0a1-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

Details for the file baresipy-1.2.0a1.tar.gz.

File metadata

  • Download URL: baresipy-1.2.0a1.tar.gz
  • Upload date:
  • Size: 48.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for baresipy-1.2.0a1.tar.gz
Algorithm Hash digest
SHA256 bc892d15c9a4398d773c35c8b50a24309a3ecec31eacae5f357f7c2a02c38f4f
MD5 58cdff9a67e000f9861cdc8de62c249e
BLAKE2b-256 4b2c0331648003e119367174218312261f4e0f777589bac2db5ddb62c2029ebc

See more details on using hashes here.

File details

Details for the file baresipy-1.2.0a1-py3-none-any.whl.

File metadata

  • Download URL: baresipy-1.2.0a1-py3-none-any.whl
  • Upload date:
  • Size: 59.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for baresipy-1.2.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 373c874996b06f63eaefb887e8ee39efc227b1721cd4c75f5a03bd3a96d6e270
MD5 31de5ddac010c80cb8f537d0daa0ceb8
BLAKE2b-256 aed22edc42fc412088ea37bbb0672c41ac32cf0f1caa11f3d5a991ea4947a709

See more details on using hashes here.

Supported by

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