Verbara.Sdk.VoiceAi.AudioSocket 2.8.0

dotnet add package Verbara.Sdk.VoiceAi.AudioSocket --version 2.8.0
                    
NuGet\Install-Package Verbara.Sdk.VoiceAi.AudioSocket -Version 2.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Verbara.Sdk.VoiceAi.AudioSocket" Version="2.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Verbara.Sdk.VoiceAi.AudioSocket" Version="2.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Verbara.Sdk.VoiceAi.AudioSocket" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Verbara.Sdk.VoiceAi.AudioSocket --version 2.8.0
                    
#r "nuget: Verbara.Sdk.VoiceAi.AudioSocket, 2.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Verbara.Sdk.VoiceAi.AudioSocket@2.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Verbara.Sdk.VoiceAi.AudioSocket&version=2.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Verbara.Sdk.VoiceAi.AudioSocket&version=2.8.0
                    
Install as a Cake Tool

Verbara.Sdk.VoiceAi.AudioSocket

AudioSocket transport for Verbara.Sdk.VoiceAi — bridges Asterisk AudioSocket streams into the Voice AI pipeline.

Installation

dotnet add package Verbara.Sdk.VoiceAi.AudioSocket

Quick Start

// Register as a hosted service (DI lifecycle managed)
services.AddAudioSocketServer(opts =>
{
    opts.ListenAddress = "0.0.0.0";
    opts.Port = 9092;
    opts.MaxConcurrentSessions = 100;
});

// Handle sessions manually (without VoiceAi pipeline)
var server = app.Services.GetRequiredService<AudioSocketServer>();
server.OnSessionStarted += async session =>
{
    await foreach (var frame in session.ReadAudioAsync(ct))
    {
        // process 20 ms PCM16 frames from Asterisk
    }
    await session.WriteAudioAsync(responseAudio, ct);
};

Features

  • AudioSocketServer — IHostedService TCP server; accepts Asterisk AudioSocket connections
  • AudioSocketSession — per-call session with ReadAudioAsync() and WriteAudioAsync() for 20 ms PCM16 frames, and an idempotent HangupAsync()
  • UUID handshake: automatically reads the channel UUID frame from Asterisk on connection
  • OnSessionStarted event for routing sessions to custom handlers
  • AddAudioSocketServer() DI extension for one-line registration
  • Zero-copy System.IO.Pipelines framing; Native AOT compatible

Ending a session

HangupAsync writes one hangup frame and closes the connection. On Asterisk 20 and later the call then goes on in the dialplan after AudioSocket(), where a bare close with the caller's audio unread fails the call; on Asterisk 18 any end from the server fails the application.

  • Idempotent. On a session that has already ended (the caller hung up, it was hung up before, or its owner disposed it) HangupAsync completes and writes nothing, so the far end receives at most one hangup frame per session. Call it on every way out without checking IsConnected first.
  • Never inside another frame. Writes are serialised per session: a hangup issued while an audio write is in flight waits for that write, so the far end reads whole frames only. Cancelling the hangup's token while it waits abandons it with an OperationCanceledException.
  • With Verbara.Sdk.VoiceAi's broker, you rarely call it yourself: the broker hangs a session up as soon as its handler returns or throws.

Starting and stopping the server

The server binds one listener and runs one accept loop in its lifetime.

  • A StartAsync while the server is running binds nothing, so a host that starts the same instance twice (as the hosted service AddAudioSocketServer registers, and again by hand) keeps one listener, and one stop releases everything.
  • The server is not restartable: a StartAsync after StopAsync binds nothing. Create a new server instead.
  • A StartAsync after DisposeAsync throws ObjectDisposedException; a StopAsync after it does nothing.
  • The stop closes the sessions it serves without a hangup frame. Register the server before the Voice AI pipeline or the Realtime bridge, so their broker stops first and ends each call with one.
  • Once the stop has begun, nothing more is registered: a connection that identified itself just before is refused with a hangup frame and never announced.

The session limit

MaxConcurrentSessions is never passed. Each channel id the server serves takes its place after the connection has identified itself, in the same atomic step that checks the limit, so a burst of calls that identify at once admits exactly the limit and refuses the rest. Each refused call receives a hangup frame and the server logs Session limit reached at Warning. A call that comes back with the UUID of a session still ending shares that session's place (below). Size the limit for the peak you want served: a deployment that ran past it in bursts on 2.6.1 and earlier now refuses those calls.

A call that comes back with the same UUID

Asterisk does not keep the AudioSocket UUID unique. A dialplan that runs AudioSocket() or Dial(AudioSocket/…) again with the UUID it saved, a transfer, or a redirect that re-enters the bot connects again with the same UUID, often before the previous session has finished ending.

  • The call is served. The new connection waits for the previous session with that UUID to end, for at most 1 second, and is then served. OnSessionStarted is raised for it only after every OnHangup handler of the previous session has returned, so state you key by ChannelId never holds two live sessions under one UUID. Keep OnHangup handlers short: while they run, the session still holds its UUID and counts in ActiveSessionCount, and a handler that takes longer than the wait makes the call that comes back be refused.
  • A UUID still live after 1 second is refused. Two concurrent calls configured with one UUID are a dialplan error: the second connection receives a hangup frame, is closed, and the server logs the ChannelIdInUse Warning naming the UUID and how long it waited. The first call is untouched.
  • What the caller hears after a refusal. Every refusal, for a UUID in use or for MaxConcurrentSessions, writes a hangup frame before closing. On Asterisk 20 and later, AudioSocket() then returns and the dialplan goes on. On Asterisk 18 any end from the server, a hangup frame included, fails the application and the call is hung up.

Give every concurrent AudioSocket call its own UUID, for example Set(BOTID=${UUID()}) once per call, and reuse it only when the same call comes back to the bot.

Documentation

See the main README for full documentation. Upgrading from 2.6.1: voice-session-ending-migration.md.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Verbara.Sdk.VoiceAi.AudioSocket:

Package Downloads
Verbara.Sdk.VoiceAi

Voice AI pipeline for Verbara.Sdk — orchestration layer for STT, TTS and conversation with turn-taking and barge-in detection.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.8.0 0 10/9/2026
2.7.0 540 10/3/2026
2.6.1 515 9/30/2026
2.6.0 745 9/24/2026
2.5.3 631 9/13/2026
2.5.2 302 9/13/2026
2.5.1 317 9/12/2026
2.5.0 386 8/25/2026
2.4.0 1,989 7/27/2026
2.3.2 682 7/20/2026
2.3.1 298 7/14/2026
2.3.0 437 7/6/2026
2.2.1 886 5/23/2026
2.2.0 198 5/20/2026
2.1.2 193 5/8/2026
2.1.1 184 5/7/2026
2.1.0 3,443 5/7/2026
2.0.0 173 5/6/2026