varapiKey=Environment.GetEnvironmentVariable("ASSEMBLYAI_API_KEY")is{Length:>0}apiKeyValue?apiKeyValue:thrownewAssertInconclusiveException("ASSEMBLYAI_API_KEY environment variable is not found.");// Create the realtime client and connect.usingvarclient=newAssemblyAIRealtimeClient();awaitclient.ConnectAsync(newUri($"wss://streaming.assemblyai.com/v3/ws?api_key={apiKey}"));// Receive the session started event.usingvarcts=newCancellationTokenSource(TimeSpan.FromSeconds(30));varreceivedSessionBegins=false;awaitforeach(varserverEventinclient.ReceiveUpdatesAsync(cts.Token)){if(serverEvent.IsBegin){receivedSessionBegins=true;Console.WriteLine($"Session started: {serverEvent.Begin?.Id}");Console.WriteLine($"Expires at: {serverEvent.Begin?.ExpiresAt}");// After session starts, send audio data.// In a real application, you would stream microphone PCM16 audio:// await client.SendAsync(audioBytes, WebSocketMessageType.Binary, true, cts.Token);// Update configuration for turn detection sensitivity.awaitclient.SendUpdateConfigurationAsync(newUpdateConfigurationPayload{EndOfTurnConfidenceThreshold=0.5,MaxTurnSilence=2000,});// For this example, manually force an endpoint to get results.awaitclient.SendForceEndpointAsync(newForceEndpointPayload());}elseif(serverEvent.IsTurn){varturn=serverEvent.Turn!;Console.WriteLine($"Turn {turn.TurnOrder}: {turn.Transcript}");Console.WriteLine($" End of turn: {turn.EndOfTurn}");Console.WriteLine($" Confidence: {turn.EndOfTurnConfidence}");if(turn.EndOfTurn==true){break;}}elseif(serverEvent.IsTermination){vartermination=serverEvent.Termination!;Console.WriteLine($"Session terminated. Audio: {termination.AudioDurationSeconds}s, Session: {termination.SessionDurationSeconds}s");break;}}// Gracefully terminate the session.awaitclient.SendSessionTerminationAsync(newSessionTerminationPayload());