SmallestAITtsLiveRealtimeClient streams Lightning audio over a WebSocket so
playback can start before synthesis finishes. Audio arrives as base64 chunk
frames, interleaved with word_timestamp frames when wordTimestamps is on,
and the stream ends with a complete frame.
Word timestamps are a WebSocket-only feature — the synchronous HTTP and SSE
routes accept the flag but ignore it. They are available on English and Hindi
voices.
This example assumes using SmallestAI; is in scope and apiKey contains your SmallestAI API key.
usingvarclient=newSmallestAIClient(apiKey);var(voiceId,_)=awaitPickContrastingVoicesAsync(client,TestContext.CancellationToken);awaitrealtime.ConnectAsync(cancellationToken:TestContext.CancellationToken);awaitrealtime.SendTtsSynthesizeAsync(voiceId:voiceId,text:"Streaming this sentence so playback can start before synthesis finishes.",wordTimestamps:true,cancellationToken:TestContext.CancellationToken);varaudioBytes=0;varwords=newList<TtsLiveEventData>();varcompleted=false;awaitforeach(var@eventinrealtime.ReceiveUpdatesAsync(TestContext.CancellationToken)){switch(@event.Status){caseTtsLiveEventStatus.Chunk:audioBytes+=@event.GetAudioBytes()?.Length??0;break;caseTtsLiveEventStatus.WordTimestampwhen@event.Datais{}data:words.Add(data);break;caseTtsLiveEventStatus.Complete:completed=true;break;default:break;}if(completed){break;}}