Both realtime clients support connection authentication for Soniox's January 15,
2027 cutoff. The MEAI streaming speech-to-text adapter authenticates automatically.
For direct server connections, pass the API key to the realtime client constructor
and leave ApiKey unset in RealtimeConfig or TtsConfig:
The regenerated full config constructors place required fields before optional
apiKey. When upgrading positional constructor calls, switch to object initializers
(as above) or named arguments to preserve field mapping.
For a browser, use the parameterless client and a temporary key from your backend:
The same constructor and connection options apply to
Soniox.Realtime.Tts.SonioxTtsRealtimeClient. Use either Bearer authentication or
subprotocols per connection; never combine them. Older temp: keys require the
Authorization header. Authentication errors arrive as server error frames after
connection, so continue reading ReceiveUpdatesAsync even when ConnectAsync
succeeds. Connections opened ahead of streaming need application keepalive messages
at least every 40 seconds; the transport keepAliveInterval alone is insufficient.
See the Soniox authentication guide.
Basic example showing how to create an authenticated Soniox client. The
SONIOX_API_KEY environment variable holds the API key issued by the
Soniox Console.
1
usingvarclient=newSonioxClient(apiKey);
List models
Fetches the list of Soniox speech-to-text models available to your workspace,
including supported languages and transcription mode (async / real-time).
Lists Soniox's shared Text-to-Speech voices for the current model. Filters can be
combined, and every returned voice includes gender, age, accent, use-case, and
style metadata. Follow NextPageCursor to continue through the catalog.
Submits a Soniox async transcription job for a public audio URL and polls
until it completes. Uses the current default async model.
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newSonioxClient(apiKey);varcreated=awaitclient.Transcriptions.CreateTranscriptionAsync(model:SonioxClient.DefaultAsyncModel,audioUrl:"https://soniox.com/media/examples/coffee_shop.mp3");// Poll until the job reaches a terminal state.while(created.StatusisTranscriptionStatus.QueuedorTranscriptionStatus.Processing){awaitTask.Delay(1000);created=awaitclient.Transcriptions.GetTranscriptionAsync(created.Id);}vartranscript=awaitclient.Transcriptions.GetTranscriptionTranscriptAsync(created.Id);// Clean up to keep the workspace tidy.awaitclient.Transcriptions.DeleteTranscriptionAsync(created.Id);
Voice cloning with Text-to-Speech
Creates a Soniox voice clone from a short reference clip, waits until it is
ready for the current TTS model, then uses the cloned voice ID in a REST
Text-to-Speech request.
Set SONIOX_VOICE_CLONE_AUDIO_PATH to a clear speech sample you have the
rights and consent to clone. Soniox accepts reference clips up to 20 seconds.
Set SONIOX_RUN_VOICE_CLONING_EXAMPLE=1 before running this paid example.
if(!IsEnvironmentFlagEnabled(RunVoiceCloningExampleFlag)&&!IsEnvironmentFlagEnabled(RunPaidTestsFlag)){thrownewAssertInconclusiveException($"Set {RunVoiceCloningExampleFlag}=1 to run this paid voice-cloning example.");}varaudioPath=Environment.GetEnvironmentVariable("SONIOX_VOICE_CLONE_AUDIO_PATH")is{Length:>0}path?path:thrownewAssertInconclusiveException("SONIOX_VOICE_CLONE_AUDIO_PATH environment variable is not found.");usingvarclient=newSonioxClient(apiKey);awaitusingvarreferenceAudio=System.IO.File.OpenRead(audioPath);varvoice=awaitclient.Voices.CreateVoiceAsync(name:$"sdk-example-{Guid.NewGuid():N}",file:referenceAudio,filename:System.IO.Path.GetFileName(audioPath));try{voice=awaitWaitForVoiceReadyAsync(client:client,voiceId:voice.Id,model:SonioxClient.DefaultTtsModel);varaudio=awaitclient.GenerateSpeechAsync(text:"Hello from a cloned Soniox voice.",voice:voice.Id.ToString(),language:"en",audioFormat:"wav",sampleRate:24000);}finally{awaitclient.Voices.DeleteVoiceAsync(voice.Id);}
Realtime Text-to-Speech
Streams text to the Soniox realtime Text-to-Speech WebSocket API. The default
test path serializes generated messages without making a network call. Set
SONIOX_RUN_REALTIME_TTS_EXAMPLE=1 to run the paid live example.
varstreamId=$"sdk-example-{Guid.NewGuid():N}";varconfig=newTtsRealtime.TtsConfig{StreamId=streamId,Model=SonioxClient.DefaultTtsModel,Language=SonioxClient.DefaultTtsLanguage,Voice="Adrian",AudioFormat=SonioxClient.DefaultTtsAudioFormat,SampleRate=24000,ReturnTimestamps=true,Speed=1.1,};vartextChunks=new[]{newTtsRealtime.TtsText{StreamId=streamId,Text="Hello from realtime ",TextEnd=false,},newTtsRealtime.TtsText{StreamId=streamId,Text="Text-to-Speech.",TextEnd=true,},};varkeepAlive=newTtsRealtime.TtsKeepAlive{KeepAlive=true};varcancel=newTtsRealtime.TtsCancel{StreamId=streamId,Cancel=true};if(!IsEnvironmentFlagEnabled(RunRealtimeTtsExampleFlag)){varconfigJson=JsonSerializer.Serialize(config,typeof(TtsRealtime.TtsConfig),TtsRealtime.TtsRealtimeSourceGenerationContext.Default);varfirstTextJson=JsonSerializer.Serialize(textChunks[0],typeof(TtsRealtime.TtsText),TtsRealtime.TtsRealtimeSourceGenerationContext.Default);varkeepAliveJson=JsonSerializer.Serialize(keepAlive,typeof(TtsRealtime.TtsKeepAlive),TtsRealtime.TtsRealtimeSourceGenerationContext.Default);varcancelJson=JsonSerializer.Serialize(cancel,typeof(TtsRealtime.TtsCancel),TtsRealtime.TtsRealtimeSourceGenerationContext.Default);return;}usingvarcancellationTokenSource=newCancellationTokenSource(TimeSpan.FromSeconds(45));awaitusingvarclient=newTtsRealtime.SonioxTtsRealtimeClient(GetRequiredEnvironmentVariable("SONIOX_API_KEY"));awaitclient.ConnectAsync(keepAliveInterval:TimeSpan.FromSeconds(15),connectTimeout:TimeSpan.FromSeconds(10),cancellationToken:cancellationTokenSource.Token);awaitclient.SendTtsConfigAsync(config,cancellationTokenSource.Token);awaitclient.SendTtsTextAsync(textChunks[0],cancellationTokenSource.Token);awaitclient.SendTtsKeepAliveAsync(keepAlive,cancellationTokenSource.Token);awaitclient.SendTtsTextAsync(textChunks[1],cancellationTokenSource.Token);varresult=awaitCollectRealtimeTtsResultAsync(client:client,streamId:streamId,cancellationToken:cancellationTokenSource.Token);
MEAI ISpeechToTextClient
SonioxClient implements Microsoft.Extensions.AI.ISpeechToTextClient, so the
same call site works with Soniox, Deepgram, Gladia, or any other MEAI STT
provider.
Non-streaming calls upload the audio to /v1/files, create a transcription
job on /v1/transcriptions, and poll until the job completes. Streaming
calls open a WebSocket to wss://stt-rt.soniox.com/transcribe-websocket.
12345678
usingvarclient=newSonioxClient(apiKey);// SonioxClient implements Meai.ISpeechToTextClient directly.Meai.ISpeechToTextClientspeechClient=client;// Metadata is exposed via ISpeechToTextClient.GetService.varmetadata=speechClient.GetService(typeof(Meai.SpeechToTextClientMetadata))asMeai.SpeechToTextClientMetadata;
MEAI AIFunction tools
Using Soniox endpoints as AIFunction tools with any Microsoft.Extensions.AI
IChatClient.
1 2 3 4 5 6 7 8 910111213
usingvarclient=newSonioxClient(apiKey);// Create AIFunction tools from the Soniox client.vartranscribeTool=client.AsTranscribeTool();vargetTool=client.AsGetTranscriptionTool();varlistModelsTool=client.AsListModelsTool();varlistLanguagesTool=client.AsListLanguagesTool();vartempKeyTool=client.AsCreateTemporaryApiKeyTool();// Verify all tools are created with the expected names.// These tools can be passed to any IChatClient for function calling.vartools=new[]{transcribeTool,getTool,listModelsTool,listLanguagesTool,tempKeyTool};
Ecosystem maintenance
This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.
Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.
Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.