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. You can dial out, answer inbound calls, stream text-to-speech or arbitrary audio into a call, send and 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 through 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.

Examples

Example Demonstrates
examples/scripted_call.py dial out, speak, send DTMF, hang up
examples/events.py subclassing BareSIP to auto-answer and speak
examples/voice_bot.py two-way OVOS STT/TTS voice bot
examples/voicemail.py voicemail / answering machine, with optional transcription
examples/call_transfer.py receptionist-style call transfer
examples/outbound_campaign.py sequential outbound dialing campaign
examples/conversational_agent.py barge-in voice agent with a pluggable response function
examples/multi_line.py concurrent multi-line SIP in one process
examples/secure_trunk.py registered account over TLS transport + SRTP media
examples/gateway_client.py driving baresipy-gateway over HTTP/WebSocket
examples/contact_list.py local JSON contact store
examples/ivr_menu.py IVR menu (DTMF-driven call routing), see docs/ivr.md

See docs/call-control.md for transfer, DTMF, barge-in, and call-metadata details used across these examples.

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() through 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()
IVR phone menus baresipy.ivr.IVRPhone, see docs/ivr.md
OVOS microphone plugin baresipy.ovos.BareSIPMicrophone
Local contact list baresipy.contacts.ContactList
Event-driven call handling override handle_* methods

Documentation

Related projects

  • OpenVoiceOS: the voice-assistant platform baresipy's optional STT/VAD/TTS pipeline is built on
  • ovos-plugin-manager: the plugin factory system used to load STT, VAD, and TTS engines
  • phoonnx: the default TTS engine used by speak()/say()

Credits

This work has been sponsored by Matt Keys, eZuce Inc

License

MIT

Metadata

Release files for baresipy 1.2.4a1

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

Source distribution (sdist)

Source distribution for baresipy 1.2.4a1
File Size Uploaded
baresipy-1.2.4a1.tar.gz 61.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for baresipy 1.2.4a1
File Interpreter ABI Platform
baresipy-1.2.4a1-py3-none-any.whl Python 3 none any Details

Total release size: 138.5 kB

Release files / baresipy-1.2.4a1.tar.gz

Download URL baresipy-1.2.4a1.tar.gz
Size 61.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8d9ecbbab33a902cd7b39830e2170b79ac2c60a44e39c1f2f95b110e27f30924
BLAKE2b-256 checksum
How to use checksums
19044b36b63a0c4cb1cf8803c273104f070158cde99003ce8afd9aea29a2f0b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / baresipy-1.2.4a1-py3-none-any.whl

Download URL baresipy-1.2.4a1-py3-none-any.whl
Size 77.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08cd1b067610e5e48492071ce5cb2f9a4c11b9dbfccf6492a2e09cb4d1aac6a7
BLAKE2b-256 checksum
How to use checksums
8fbdb6c25fa5ca02ff314cdb28e848d2816f983594862a0b92f449b6ad2672c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14
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