Skip to content

Repository files navigation

Soniox

Modern .NET SDK for Soniox generated from the provider's OpenAPI definition with AutoSDK.

Nuget packagedotnetLicense: MITDiscord

Generated from the source spec

Built from Soniox's docs OpenAPI definition so the SDK stays close to the upstream API surface.

Auto-updated

Designed for fast regeneration and low-friction updates when the upstream API changes without breaking compatibility.

Modern .NET

Targets current .NET practices including nullability, trimming, NativeAOT awareness, and source-generated serialization.

Docs from examples

Examples stay in sync between the README, MkDocs site, and integration tests through the AutoSDK docs pipeline.

Usage

usingSoniox;usingvarclient=newSonioxClient(apiKey);

MeaiSpeechToTextParsing

varupdate=SonioxClient.ParseServerFrame(""" { "tokens": [ { "text": "привет", "start_ms": 10, "end_ms": 320, "confidence": 0.97, "speaker": "speaker_0", "language": "ru", "is_final": true } ], "final_audio_proc_ms": 320, "total_audio_proc_ms": 400, "finished": false } """,responseId:"response",outvarfinished);vartokens=update.AdditionalProperties![SonioxSpeechToTextPropertyNames.Tokens].Which;update.AdditionalProperties[SonioxSpeechToTextPropertyNames.Speakers]

Construct a SonioxClient

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.

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).

usingvarclient=newSonioxClient(apiKey);varresponse=awaitclient.Models.GetModelsAsync();foreach(varmodelinresponse.Models){}

Transcribe from URL (async)

Submits a Soniox async transcription job for a public audio URL and polls until it completes. Uses the current default async model.

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.Queued or TranscriptionStatus.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.

SonioxClient.DefaultTtsModel targets Soniox TTS v2 (tts-rt-v2) for both REST and realtime generation. Use SonioxClient.TtsRealtimeV1ModelId only when you explicitly need the backward-compatible v1 model.

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{ApiKey=GetOptionalEnvironmentVariable("SONIOX_API_KEY")??"test-key",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);configJson.Should().Contain("\"return_timestamps\":true");configJson.Should().Contain("\"speed\":1.1");return;}usingvarcancellationTokenSource=newCancellationTokenSource(TimeSpan.FromSeconds(45));awaitusingvarclient=newTtsRealtime.SonioxTtsRealtimeClient();awaitclient.ConnectAsync(keepAliveInterval:TimeSpan.FromSeconds(15),connectTimeout:TimeSpan.FromSeconds(10),cancellationToken:cancellationTokenSource.Token);config.ApiKey=GetRequiredEnvironmentVariable("SONIOX_API_KEY");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);result.CharacterTimestampCount.Should().BeGreaterThan(0);

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.

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.

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.

Support

Bugs

Open an issue in tryAGI/Soniox.

Ideas and questions

Use GitHub Discussions for design questions and usage help.

Community

Join the tryAGI Discord for broader discussion across SDKs.

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.

About

Generated C# SDK for Soniox — real-time and async speech-to-text with 60+ languages, translation, speaker diarization, and language identification.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages