Connect to Stream and Transcribe APIs, handle real-time events, and manage session lifecycle
The SDK wraps both WebSocket APIs — Stream and Transcribe — with a consistent async/event-driven interface: factory methods to create connections, ConnectAsync() to open and configure, and typed Event<T> fields to subscribe to messages.
Both WebSocket APIs require a handshake before audio can flow. After the connection opens, the SDK sends the configuration automatically and waits for the server to respond with CONFIG_ACCEPTED. Only then does ConnectAsync() return. If configuration is rejected, ConnectAsync() throws.
Stream
Transcribe
C# .NET
var stream = await client.CreateStreamApiAsync(interactionId);stream.StreamTranscriptMessage.Subscribe(message =>{ Console.WriteLine($"Transcript: {message.Data.Text}");});stream.StreamFactsMessage.Subscribe(_ =>{ Console.WriteLine("Facts received");});await stream.ConnectAsync(new StreamConfig{ Transcription = new StreamConfigTranscription { PrimaryLanguage = "en", Participants = new[] { new StreamConfigParticipant { Channel = 0, Role = StreamConfigParticipantRole.Doctor }, }, }, Mode = new StreamConfigMode { Type = StreamConfigModeType.Facts, OutputLocale = "en", },});await stream.Send(audioBytes);
C# .NET
var transcribe = await client.CreateTranscribeApiAsync();transcribe.TranscribeTranscriptMessage.Subscribe(message =>{ Console.WriteLine($"Transcript: {message.Data.Text}");});await transcribe.ConnectAsync(new TranscribeConfig{ PrimaryLanguage = "en", AutomaticPunctuation = true,});// Send audio data (e.g. from a microphone stream)await transcribe.Send(audioBytes);
Subscribe to events before calling ConnectAsync(). The SDK emits Connected and potentially early message events as soon as the WebSocket opens — subscribing after ConnectAsync() returns means those events are already gone.
If you want to manage the handshake manually and only use the SDK for types and reconnection, omit configuration from ConnectAsync(). The socket opens without waiting for CONFIG_ACCEPTED — you are responsible for sending the config message yourself and waiting for StreamConfigStatusMessage before sending audio.
C# .NET
var stream = await client.CreateStreamApiAsync(interactionId);stream.StreamConfigStatusMessage.Subscribe(msg =>{ if (msg.Status == StreamConfigStatusMessageStatus.ConfigAccepted) Console.WriteLine("Configuration accepted — ready to send audio"); else Console.WriteLine($"Configuration denied: {msg.Status}");});// Connect without configuration — does not wait for CONFIG_ACCEPTEDawait stream.ConnectAsync();// Send configuration manuallyawait stream.Send(new StreamConfigMessage{ Configuration = new StreamConfig { Transcription = new StreamConfigTranscription { PrimaryLanguage = "en", Participants = new[] { new StreamConfigParticipant { Channel = 0, Role = StreamConfigParticipantRole.Doctor }, }, }, Mode = new StreamConfigMode { Type = StreamConfigModeType.Facts, OutputLocale = "en" }, },});