usingvarclient=newElevenLabsClient(apiKey);usingvarcts=newCancellationTokenSource(TimeSpan.FromSeconds(30));// Open a realtime speech-to-text session.awaitusingvarsession=awaitclient.ConnectRealtimeAsync(newRealtimeSpeechToTextOptions{AudioFormat=RealtimeAudioFormat.Pcm24000,CommitStrategy=RealtimeCommitStrategy.Manual,},cancellationToken:cts.Token);// Load a WAV file and convert it to PCM16 samples.byte[]wavBytes=awaitFile.ReadAllBytesAsync(Path.Combine(AppContext.BaseDirectory,"Resources","hello-in-russian-24k-pcm16.wav"),cts.Token);var(pcm,sampleRate,channels)=ReadWavPcm16(wavBytes);// Send the audio in 0.5 second chunks and commit the final chunk.constintsamplesPerChunk=12000;for(varoffset=0;offset<pcm.Length;offset+=samplesPerChunk){varcount=Math.Min(samplesPerChunk,pcm.Length-offset);varbytes=newbyte[count*2];Buffer.BlockCopy(pcm,offset*2,bytes,0,bytes.Length);varcommit=offset+count>=pcm.Length;awaitsession.SendAudioChunkAsync(bytes,sampleRate,commit,cancellationToken:cts.Token);}// Read events until the service returns a final transcript.string?transcript=null;awaitforeach(varevtinsession.ReadEventsAsync(cts.Token)){switch(evt){caseSessionStartedEventstarted:Console.WriteLine($"Session started: {started.SessionId}");break;casePartialTranscriptEventpartial:Console.WriteLine($"Partial: {partial.Text}");break;caseCommittedTranscriptEventcommitted:transcript=committed.Text;Console.WriteLine($"Final: {committed.Text}");break;caseCommittedTranscriptWithTimestampsEventcommittedWithTimestamps:transcript=committedWithTimestamps.Text;Console.WriteLine($"Final: {committedWithTimestamps.Text}");break;caseErrorEventerror:thrownewInvalidOperationException($"ElevenLabs error: {error.ErrorType} - {error.Error}");}if(!string.IsNullOrWhiteSpace(transcript)){break;}}