|
1 | | -# AliceAndBob Example |
| 1 | +# AliceAndBob - OpenAI Realtime WebRTC Demo |
2 | 2 |
|
3 | | -Runs two OpenAI WebRTC sessions ("Alice" and "Bob") and pipes their audio |
4 | | -between each other. A simple OpenGL scope visualises which side is speaking. |
| 3 | +**AliceAndBob** is a demonstration project that connects two [OpenAI Realtime API](https://platform.openai.com/docs/guides/realtime) WebRTC sessions—nicknamed *Alice* and *Bob*—and pipes their audio between one another. This simulates a live, bi-directional conversation between two AI agents. A Windows-based OpenGL audio visualisation displays which side is currently speaking. |
5 | 4 |
|
6 | | -## Usage |
| 5 | +--- |
| 6 | + |
| 7 | +## 🎯 Features |
| 8 | + |
| 9 | +- Initiates and maintains two OpenAI WebRTC sessions. |
| 10 | +- Forwards audio from Alice to Bob and vice versa. |
| 11 | +- Uses [SIPSorcery](https://github.com/sipsorcery/sipsorcery) WebRTC libraries and [NAudio](https://github.com/naudio/NAudio) for media handling. |
| 12 | +- Visualises audio signal strength in real-time using a WinForms OpenGL scope. |
| 13 | +- Shows how to work with: |
| 14 | + - WebRTC connections |
| 15 | + - OpenAI Realtime API |
| 16 | + - Audio frame decoding and manipulation |
| 17 | + - Session updates and message prompting via data channels |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## 🛠 Requirements |
| 22 | + |
| 23 | +- **Operating System**: Windows |
| 24 | +- **.NET Version**: [.NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) |
| 25 | +- **Audio**: A working input/output device (e.g., microphone, speakers) |
| 26 | +- **API Access**: OpenAI API key with access to Realtime features |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 🚀 Getting Started |
| 31 | + |
| 32 | +### 1. Clone the Repository |
| 33 | + |
| 34 | +```bash |
| 35 | +git clone https://github.com/sipsorcery-org/SIPSorcery.OpenAI.WebRTC.git |
| 36 | +cd SIPSorcery.OpenAI.WebRTC/examples/AliceAndBob |
| 37 | +``` |
| 38 | + |
| 39 | +### 2. Set Your OpenAI API Key |
| 40 | + |
| 41 | +Set the `OPENAI_API_KEY` environment variable in your terminal: |
| 42 | + |
| 43 | +```bash |
| 44 | +set OPENAI_API_KEY="<your-openai-api-key>" |
| 45 | +``` |
| 46 | + |
| 47 | +### 3. Run the Application |
7 | 48 |
|
8 | 49 | ```bash |
9 | | -export OPENAI_API_KEY="<your OpenAI key>" |
10 | 50 | dotnet run |
11 | 51 | ``` |
12 | 52 |
|
13 | | -You'll need a Windows machine with audio devices and .NET 8.0 installed. |
| 53 | +You should see a WinForms window showing two audio scopes—one for Alice and one for Bob—while the agents begin a real-time audio exchange. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## 📷 Application Preview |
| 58 | + |
| 59 | +The `Program.cs` does the following: |
| 60 | + |
| 61 | +- Creates a WinForms UI thread for audio scope visualization. |
| 62 | +- Starts two OpenAI WebRTC sessions (`Alice` and `Bob`). |
| 63 | +- Establishes WebRTC peer connections. |
| 64 | +- Routes audio received from Alice to Bob, and vice versa. |
| 65 | +- Uses OpenAI’s `DataChannelMessenger` to: |
| 66 | + - Send a `response.create` event from Alice saying “Hi!” |
| 67 | + - Change Bob’s voice using a `session.update` event. |
| 68 | +- Decodes and visualizes incoming audio frames. |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 📦 Key Technologies |
| 73 | + |
| 74 | +| Component | Role | |
| 75 | +|-------------------|--------------------------------------------------| |
| 76 | +| `SIPSorcery` | WebRTC signaling, media transport, SDP | |
| 77 | +| `NAudio` | Windows audio capture/playback (used internally) | |
| 78 | +| `OpenAI Realtime` | API endpoints for streaming AI audio responses | |
| 79 | +| `WinForms` | UI for displaying real-time audio signal | |
| 80 | +| `OpenGL` | Audio waveform visualization | |
| 81 | +| `Serilog` | Structured logging to console | |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## 🧩 Files of Interest |
| 86 | + |
| 87 | +| File | Description | |
| 88 | +|-----------------------|--------------------------------------------------| |
| 89 | +| `Program.cs` | Main entry point. Starts sessions and handles logic. | |
| 90 | +| `FormAudioScope.cs` | Audio visualisation using WinForms and OpenGL. | |
| 91 | +| `WebRTCEndPoint.cs` | WebRTC peer connection wrapper for OpenAI. | |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## 📝 License |
| 96 | + |
| 97 | +This project is licensed under the **BSD 3-Clause License** with an additional **BY-NC-SA** restriction. See [`LICENSE.md`](./LICENSE.md) for full terms. |
0 commit comments