Skip to main content

A FastAPI router + Twilio⇆OpenAI realtime streaming helper

Project description

awesome_caller_boi

A small Python package that exposes a FastAPI router to connect Twilio’s voice streaming directly to the OpenAI realtime API (GPT-4o). It handles incoming calls, establishes the WebSocket media stream with Twilio, forwards audio to OpenAI, and sends back OpenAI’s audio response to the caller.

Features

  • Provides a FastAPI router for Twilio voice webhooks.
  • Streams inbound audio from Twilio to OpenAI in real time.
  • Encodes and forwards OpenAI’s audio responses back to Twilio.
  • Automatically handles speech interruptions (caller starts speaking mid-response).
  • Easy to configure with your own get_system_message() and get_system_greeting() callbacks.
  • Put your OpenAi key in your enviornment variables and call it OPENAI_API_KEY

Installation

From PyPI (once published):

pip install awesome_caller_boi

## Usage Example 

from awesome_caller_boi.call_handler import create_call_router
from models.transcripts import Transcript

def my_middleware_fn(transcript: Transcript) -> dict:
    # extract name, order, etc., or send it to your database
    print("Got a finished call from:", transcript.phone_number)
    print("Full transcript text:", transcript.call_text)
    return {"status": "ok"}

app.include_router(
    create_call_router(
        get_system_message=my_system_message,
        get_system_greeting=my_system_greeting,
        voice="alloy",
        on_call_complete=my_middleware_fn
    )
)

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

awesome_caller_boi-0.2.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

awesome_caller_boi-0.2.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file awesome_caller_boi-0.2.1.tar.gz.

File metadata

  • Download URL: awesome_caller_boi-0.2.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for awesome_caller_boi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3370eff6e9fa0340c57052d3fed2d4c8c9fb7099b4d70a6a9392fd2be2b2aa55
MD5 cd2804854721cd469488df16c4df51cf
BLAKE2b-256 d638b9002c674e43862f5e5c43d850c84d19b0a651973bab9e858f4a34fa19d8

See more details on using hashes here.

File details

Details for the file awesome_caller_boi-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for awesome_caller_boi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bc130992b46040b4e6458644e275ad1d8d7f71872883c23b737349acb6ea4627
MD5 129fb14f53b5d092a59b3705926d7df3
BLAKE2b-256 b4f2c02c6e85b40678cf9f99baac2623246f7c8f5f4e3c7fcb8ee3cf98dfcab3

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 Pingdom Monitoring Sentry Error logging StatusPage Status page