The application is a fully functional AI phone agent written in PHP using Swoole, the OpenAI API as the language model, and Deepgram Flux for state-of-the-art speech recognition. It’s designed to make the AI voice sound more human and less robotic.
When someone dials your Twilio number, Twilio requests TwiML from the application’s "/twiml" endpoint. The endpoint returns a <ConversationRelay> verb inside a <Connect> block, which tells Twilio to open a [WebSocket] connection to your server and hand the call off to Conversation Relay.
From that point on, Conversation Relay acts as the voice pipeline. It transcribes everything the caller says using speech-to-text (STT) and sends the transcript to your WebSocket server as a JSON message. Your server calls an AI model with the transcript, streams the response back over the WebSocket, and Conversation Relay synthesises each token into speech using {}[Text-to-Speech (TTS)], playing it to the caller in real time.
To run the app locally, you need the following:
-
An ngrok account
-
PHP 8.4 or later
-
A Twilio account with a voice-capable phone number
-
Clone or download this repository
-
Install the dependencies:
composer install
-
Rename the .env.example file to .env
-
Start ngrok listening on port 9051 and :
ngrok http 9051
-
Copy the Forwarding URL from the terminal output
-
Configure your Twilio Account:
-
Log into the Twilio Console
-
Navigate through Phone Numbers › Manage › Active Numbers
-
Click your voice-capable phone number to open its configuration page
-
Under the Voice Configuration section, set:
-
A Call Comes In to "Webhook" and enter the URL for your TwiML endpoint. It will be your ngrok Forwarding URL, plus the suffix "/twiml", e.g., https://1234abcd.ngrok.app/twiml
-
Set the HTTP method to "HTTP POST"
-
-
Scroll down to the bottom of the page and click Save Configuration
-
-
Set the Required Environment Variables
-
Set the ngrok Forwarding URL’s domain, minus the protocol, i.e., "https://", as the value of the
DOMAINvariable in .env -
Set your OpenAI API key as the value of
OPENAI_API_KEYin .env
-
-
Start the Application
php index.php
This will start four workers listening on port 9051.
NoteTo stop the application, press Ctrl+C.
If you want to contribute to the project, whether you have found issues with it or just want to improve it, here’s how:
-
Issues: ask questions and submit your feature requests, bug reports, etc
-
Pull requests: send your improvements

