Verbara.Sdk.VoiceAi.OpenAiRealtime
2.10.1
dotnet add package Verbara.Sdk.VoiceAi.OpenAiRealtime --version 2.10.1
NuGet\Install-Package Verbara.Sdk.VoiceAi.OpenAiRealtime -Version 2.10.1
<PackageReference Include="Verbara.Sdk.VoiceAi.OpenAiRealtime" Version="2.10.1" />
<PackageVersion Include="Verbara.Sdk.VoiceAi.OpenAiRealtime" Version="2.10.1" />
<PackageReference Include="Verbara.Sdk.VoiceAi.OpenAiRealtime" />
paket add Verbara.Sdk.VoiceAi.OpenAiRealtime --version 2.10.1
#r "nuget: Verbara.Sdk.VoiceAi.OpenAiRealtime, 2.10.1"
#:package Verbara.Sdk.VoiceAi.OpenAiRealtime@2.10.1
#addin nuget:?package=Verbara.Sdk.VoiceAi.OpenAiRealtime&version=2.10.1
#tool nuget:?package=Verbara.Sdk.VoiceAi.OpenAiRealtime&version=2.10.1
Verbara.Sdk.VoiceAi.OpenAiRealtime
OpenAI Realtime API bridge for Verbara.Sdk.VoiceAi — persistent WebSocket session with function calling, transcript events, and dual-loop audio streaming.
Installation
dotnet add package Verbara.Sdk.VoiceAi.OpenAiRealtime
Quick Start
// Prerequisite: register AudioSocket transport
services.AddAudioSocketServer(opts => opts.Port = 9092);
// Register the bridge (replaces the STT→LLM→TTS chain)
services.AddOpenAiRealtimeBridge(opts =>
{
opts.ApiKey = configuration["OpenAI:ApiKey"]!;
opts.Model = "gpt-realtime";
opts.Voice = "alloy";
opts.Instructions = "You are a helpful call center assistant.";
opts.VadMode = VadMode.ServerSide;
})
.AddFunction<GetAccountBalanceFunction>(); // optional tool functions
// Subscribe to bridge events
var bridge = app.Services.GetRequiredService<OpenAiRealtimeBridge>();
bridge.Events.Subscribe(evt =>
{
if (evt is RealtimeTranscriptEvent t && t.IsFinal)
Console.WriteLine($"[{t.ChannelId}] {t.Text}");
});
Features
OpenAiRealtimeBridge—ISessionHandlerthat opens a WebSocket to OpenAI Realtime API per call- Dual audio loops: inbound PCM16 → base64 → OpenAI, OpenAI audio delta → PCM16 → Asterisk
- Automatic resampling between Asterisk 8 kHz and OpenAI 24 kHz via
ResamplerFactory - Function calling: register
IRealtimeFunctionHandlerimplementations withAddFunction<T>(), each call bounded byFunctionCallTimeout(default 30 s; writtenhh:mm:ssin configuration): a function that outlasts it is answered{"error":"timeout"}, logged at Warning, counted inopenai_realtime.function_calls.timed_outand no longer awaited (migration guide) - Observable
Eventsstream (RealtimeTranscriptEvent,RealtimeFunctionCalledEvent,RealtimeResponseStartedEvent, etc.) AddOpenAiRealtimeBridge()andAddFunction<T>()DI extension methods- Native AOT compatible (AOT-safe JSON via
System.Text.Jsonsource generation)
When the conversation ends
The bridge runs one Realtime conversation per AudioSocket session, and the session broker that
AddOpenAiRealtimeBridge registers ends the line as soon as the bridge returns:
- The vendor closes the conversation. The bridge answers the vendor's close with its own, also
while an input audio send is in flight, and its close code decides the session (a normal close
completes it, a failure close fails it). The bridge then returns and the broker hangs the line up with
one hangup frame. On the
AudioSocket()route of Asterisk 20 and later the caller goes on in the dialplan at once (measured 2026-10-02 on 20.20.1, 22.9.0 and 23.4.1: 60 of 60 calls, within 2 ms of the bridge returning); on an ARIexternalMediaroute the channel leaves Stasis with the caller still in your bridge (60 of 60). Put what the caller should hear next in the dialplan or your ARI application. On Asterisk 18 the application fails and the call is hung up. - The caller hangs up. The bridge stops forwarding vendor audio and sends its close. It keeps reading until the vendor answers or the existing 10-second bound expires, including when an audio write failed because the caller's transport ended. A normal vendor close completes the session; a failure close fails it, even after the caller left.
- The host stops. A graceful stop hangs up every live call with a frame and waits for each conversation to return, within the host's shutdown budget. A conversation the host cancels returns once both of its audio loops have ended, without waiting for a function still running, and an event a session raises after the bridge was disposed is dropped and logged at Debug rather than thrown inside the session.
If the vendor loop ends while an input audio send is stalled, the bridge attempts its terminal close under the existing write discipline and 10-second close bound. A send still blocking that attempt at the bound is ended by aborting the transport; both loops finish before their resources are released. This cleanup does not replace the vendor's close code or the receive failure that ended the session.
An event whose JSON the bridge cannot decode does not end the conversation. An error event whose JSON cannot be
decoded is published as a RealtimeErrorEvent carrying the raw frame, as a decoded one is published with its message;
any other such event is skipped, logged at Warning and counted on openai_realtime.frames.unparseable (tagged
voiceai.provider), and the call goes on. An audio delta whose delta is null or not valid base64 is skipped, logged
at Warning and counted on openai_realtime.frames.unparseable like any other event the bridge cannot read; one whose
delta is empty, or too short to make one sample at the caller's rate, carries no audio and is skipped without a count;
the call goes on either way. An event that decodes but whose handling fails — an Events subscriber that throws —
still ends the session and counts in openai_realtime.sessions.failed.
Every session the bridge starts is counted in exactly one of openai_realtime.sessions.completed, .failed or
.cancelled. A session is cancelled only when the token handed to the bridge was cancelled (the host, a stop that
is no longer graceful, the broker's disposal), and its openai_realtime.session.duration_ms sample carries
voiceai.ending = session-cancelled. A normal vendor close, or an unanswered close after the caller's
hangup, is completed; a vendor failure close is failed, including after a hangup. A host cancellation that
aborts an input audio send is still cancelled, even when the socket reports a state error.
Register AddAudioSocketServer before AddOpenAiRealtimeBridge (the prerequisite above), so the
broker stops before the server and every call ends with a hangup frame.
Health
AddOpenAiRealtimeBridge registers the openai-realtime health entry (RealtimeHealthCheck). It reports
Unhealthy with no API key configured, Degraded once the vendor rejected the bridge's last 3 consecutive sessions
(an upgrade refused with a 4xx, or a failure close before any vendor audio reached the caller), and Healthy
otherwise, again from the first session the vendor serves. A session the host cancelled, or one that ended on a
transport failure, counts neither way. Its data carries consecutiveRejections and, once a rejection happened,
lastRejection and lastRejectionAt. Rejections never report Unhealthy, so a default health endpoint keeps
answering 200.
Documentation
See the main README for full documentation. Upgrading from 2.6.1: voice-session-ending-migration.md and voice-bounds-migration.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- System.Reactive (>= 7.0.0)
- Verbara.Sdk.Audio (>= 2.10.1)
- Verbara.Sdk.VoiceAi (>= 2.10.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.10.1 | 393 | 11/17/2026 |
| 2.10.0 | 268 | 11/16/2026 |
| 2.9.0 | 1,456 | 10/29/2026 |
| 2.8.0 | 1,581 | 10/9/2026 |
| 2.7.0 | 577 | 10/3/2026 |
| 2.6.1 | 479 | 9/30/2026 |
| 2.6.0 | 720 | 9/24/2026 |
| 2.5.3 | 612 | 9/13/2026 |
| 2.5.2 | 259 | 9/13/2026 |
| 2.5.1 | 290 | 9/12/2026 |
| 2.5.0 | 347 | 8/25/2026 |
| 2.4.0 | 209 | 7/27/2026 |
| 2.3.2 | 147 | 7/20/2026 |
| 2.3.1 | 137 | 7/14/2026 |
| 2.3.0 | 148 | 7/6/2026 |
| 2.2.1 | 155 | 5/23/2026 |
| 2.2.0 | 136 | 5/20/2026 |
| 2.1.2 | 146 | 5/8/2026 |
| 2.1.1 | 143 | 5/7/2026 |
| 2.1.0 | 3,391 | 5/7/2026 |