|
1 |
| -# compliance-platform |
2 |
| -Compliance Platform for software houses |
| 1 | +# OpenAI Realtime API + Twilio Voice Integration |
| 2 | + |
| 3 | +A powerful integration that combines OpenAI's Realtime API with Twilio's Voice services to create interactive voice calls with AI responses. This project enables real-time voice conversations between humans and AI, making it perfect for compliance monitoring, customer service automation, and other voice-based AI applications. |
| 4 | + |
| 5 | +- AI sales agent |
| 6 | +- AI Support Agent |
| 7 | +- AI Cold Calling |
| 8 | +- AI Compliance |
| 9 | + |
| 10 | +## Features |
| 11 | + |
| 12 | +- Real-time voice streaming between Twilio and OpenAI |
| 13 | +- Automatic speech detection and response cancellation |
| 14 | +- Configurable voice settings and system prompts |
| 15 | +- Environment-based configuration |
| 16 | +- WebSocket-based communication |
| 17 | +- Support for G711 ULAW audio format |
| 18 | +- Interrupt handling for natural conversation flow |
| 19 | +- Session management and real-time updates |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +Before you begin, ensure you have: |
| 24 | + |
| 25 | +- Python 3.8 or higher |
| 26 | +- An OpenAI API key with Realtime API access |
| 27 | +- A Twilio account with: |
| 28 | + - Account SID |
| 29 | + - Auth Token |
| 30 | + - Phone Number |
| 31 | +- ngrok or similar tool for exposing local server to the internet |
| 32 | + |
| 33 | +## Installation |
| 34 | + |
| 35 | +1. Clone the repository: |
| 36 | +```bash |
| 37 | +git clone https://github.com/rehan-dev/ai-call-agent.git |
| 38 | +cd ai-call-agent |
| 39 | +``` |
| 40 | + |
| 41 | +2. Install required dependencies: |
| 42 | +```bash |
| 43 | +pip install -r requirements.txt |
| 44 | +``` |
| 45 | + |
| 46 | +3. Create a `.env` file in the root directory with your credentials: |
| 47 | +```env |
| 48 | +OPENAI_API_KEY=your_openai_api_key |
| 49 | +TWILIO_ACCOUNT_SID=your_twilio_account_sid |
| 50 | +TWILIO_AUTH_TOKEN=your_twilio_auth_token |
| 51 | +TWILIO_PHONE_NUMBER=your_twilio_phone_number |
| 52 | +NGROK_URL=your_ngrok_url |
| 53 | +PORT=5050 |
| 54 | +``` |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +1. Start the server: |
| 59 | +```bash |
| 60 | +uvicorn main:app --port 5050 |
| 61 | +``` |
| 62 | + |
| 63 | +2. Expose your local server using ngrok: |
| 64 | +```bash |
| 65 | +ngrok http 5050 |
| 66 | +``` |
| 67 | + |
| 68 | +3. Update your Twilio Voice webhook URL to point to your ngrok URL + `/outgoing-call` |
| 69 | + |
| 70 | +4. Make a call using the API endpoint: |
| 71 | +```bash |
| 72 | +curl -X POST "http://localhost:5050/make-call" -H "Content-Type: application/json" -d '{"to_phone_number": "+1234567890"}' |
| 73 | +``` |
| 74 | + |
| 75 | +## Project Structure |
| 76 | + |
| 77 | +``` |
| 78 | +. |
| 79 | +├── main.py # Main application file |
| 80 | +├── prompts/ |
| 81 | +│ └── system_prompt.txt # System instructions for AI |
| 82 | +├── requirements.txt # Python dependencies |
| 83 | +├── .env # Environment variables |
| 84 | +├── .gitignore # Git ignore file |
| 85 | +├── LICENSE # License file |
| 86 | +└── README.md # Project documentation |
| 87 | +``` |
| 88 | + |
| 89 | +## Configuration |
| 90 | + |
| 91 | +### Environment Variables |
| 92 | + |
| 93 | +- `OPENAI_API_KEY`: Your OpenAI API key |
| 94 | +- `TWILIO_ACCOUNT_SID`: Your Twilio Account SID |
| 95 | +- `TWILIO_AUTH_TOKEN`: Your Twilio Auth Token |
| 96 | +- `TWILIO_PHONE_NUMBER`: Your Twilio phone number |
| 97 | +- `NGROK_URL`: Your ngrok URL |
| 98 | +- `PORT`: Server port (default: 5050) |
| 99 | + |
| 100 | +### System Prompt |
| 101 | + |
| 102 | +The AI's behavior can be customized by modifying the system prompt in `prompts/system_prompt.txt`. |
| 103 | + |
| 104 | +## API Endpoints |
| 105 | + |
| 106 | +- `GET /`: Health check endpoint |
| 107 | +- `POST /make-call`: Initiate a new call |
| 108 | +- `POST /outgoing-call`: Webhook for Twilio voice calls |
| 109 | +- `WebSocket /media-stream`: WebSocket endpoint for media streaming |
| 110 | + |
| 111 | +## Contributing |
| 112 | + |
| 113 | +Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. |
| 114 | + |
| 115 | +1. Fork the repository |
| 116 | +2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
| 117 | +3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
| 118 | +4. Push to the branch (`git push origin feature/AmazingFeature`) |
| 119 | +5. Open a Pull Request |
| 120 | + |
| 121 | +## License |
| 122 | + |
| 123 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 124 | + |
| 125 | +## Author |
| 126 | + |
| 127 | +**Rehan Khan** |
| 128 | +[LinkedIn Profile](https://www.linkedin.com/in/rehankhantht/) |
| 129 | + |
| 130 | +## Acknowledgments |
| 131 | + |
| 132 | +- OpenAI for providing the Realtime API |
| 133 | +- Twilio for their excellent voice services |
| 134 | +- The open-source community for inspiration and support |
| 135 | + |
| 136 | +## Disclaimer |
| 137 | + |
| 138 | +This project is not officially affiliated with OpenAI or Twilio. Use at your own risk. |
0 commit comments