Welcome! This Node.js application integrates Asterisk 22 with the OpenAI Realtime API to provide a voice-based virtual assistant for SIP calls. It processes audio in real-time and displays user and assistant transcriptions in the console.
- Real-time audio processing with Asterisk and OpenAI.
- Console transcriptions for user and assistant speech.
- Clean resource management (channels, bridges, WebSocket, RTP).
- Configurable via
config.conf
(e.g., API key, prompt).
Category | Details |
---|---|
OS | Ubuntu 24.04 LTS |
Software | - Node.js v18.20.8+ (node -v )- Asterisk 22 with ARI enabled ( http.conf , ari.conf )- Node dependencies: ari-client , ws , uuid , winston , chalk , dotenv |
Network | - Ports: 8088 (ARI), 12000+ (RTP) - Access to wss://api.openai.com/v1/realtime |
Credentials | - OpenAI API key (OPENAI_API_KEY )- ARI credentials ( asterisk /asterisk ) |
- Install prerequisites:
sudo apt update sudo apt install nodejs npm asterisk
- Configure Asterisk:
- Enable HTTP
Add the following lines at the end of the file:
sudo nano /etc/asterisk/http.conf
enabled=yes bindaddr=0.0.0.0 bindport=8088
- Configure ARI
Add the following lines at the end of the file:
sudo nano /etc/asterisk/ari.conf
[asterisk] type=user password=asterisk
- Add dialplan
Add the following lines at the end of the file:
sudo nano /etc/asterisk/extensions.conf
[default] exten => 9999,1,Answer() same => n,Stasis(asterisk_to_openai_rt) same => n,Hangup()
- Configure SIP Extensions
Add the following lines at the end of the file to configure SIP extension 300 that can call 9999:
sudo nano /etc/asterisk/pjsip.conf
[transport-udp] type=transport protocol=udp bind=0.0.0.0 external_media_address=3.89.115.249 ; Required: Replace with your EC2 instance's public IP from AWS console external_signaling_address=3.89.115.249 ; Required: Replace with your EC2 instance's public IP from AWS console local_net=172.31.0.0/16 ; Optional: Adjust to your VPC CIDR if different [300] type=endpoint context=default disallow=all allow=ulaw auth=300 aors=300 direct_media=no media_use_received_transport=yes rtp_symmetric=yes force_rport=yes rewrite_contact=yes dtmf_mode=auto [300] type=auth auth_type=userpass password=pass300 username=300 [300] type=aor max_contacts=2
- Restart Asterisk:
sudo systemctl restart asterisk
- Enable HTTP
- Clone the repository and install dependencies:
git clone https://github.com/infinitocloud/asterisk_to_openai_rt_community.git cd asterisk_to_openai_rt_community npm install
- Edit
config.conf
in the project root and add yourOPENAI_API_KEY
in the designated field:OPENAI_API_KEY=
- Run the application:
node index.js
- Make a SIP call to the configured extension (e.g.,
9999
). - Interact with the assistant (e.g., say "Hi", "What is your name?").
- Check console for transcriptions:
O-0005 | 2025-06-28T04:15:01.924Z [INFO] [OpenAI] Assistant transcription: Hello! I'm Sofia... O-0010 | 2025-06-28T04:15:08.045Z [INFO] [OpenAI] User command transcription: What is your name?
- End the call or press
Ctrl+C
to stop.
- Error:
OPENAI_API_KEY is missing
: VerifyOPENAI_API_KEY
inconfig.conf
. - Error:
ARI connection error
: Check Asterisk (sudo systemctl status asterisk
, port 8088). - No transcriptions: Set
LOG_LEVEL=debug
inconfig.conf
. - Debug commands:
- Asterisk logs:
tail -f /var/log/asterisk/messages
- Node.js debug:
node --inspect index.js
- Asterisk logs:
- Wrong password on SIP registration: Ensure the SIP phone username is
300
and password ispass300
. Verify the server IP matches your Asterisk instance. - No audio: Ensure
external_media_address
andexternal_signaling_address
inpjsip.conf
match your EC2 public IP. Verify RTP ports (12000+) are open in EC2 security group and local firewall. Updateasterisk.js
external_host
to use the server’s IP.
- Report issues with logs and steps to reproduce.
- Submit pull requests via GitHub.
- License: MIT (see
LICENSE
).