Skip to content

Realtime Avatar Client

Test the IRealtimeAvatarClient adapter for Simli realtime sessions.

This example assumes using Simli; is in scope and apiKey contains your Simli API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var apiKey =
    Environment.GetEnvironmentVariable("SIMLI_API_KEY") is { Length: > 0 } key
        ? key
        : throw new AssertInconclusiveException("SIMLI_API_KEY environment variable is not found.");

var faceId =
    Environment.GetEnvironmentVariable("SIMLI_FACE_ID") is { Length: > 0 } id
        ? id
        : "default"; // Use default face if not specified

var client = new SimliClient(apiKey);

// Create and connect via the unified interface
await using var avatar = await SimliRealtimeAvatarClient.ConnectAsync(
    client, faceId);

// Verify the adapter implements IRealtimeAvatarClient
tryAGI.RealtimeAvatar.IRealtimeAvatarClient realtimeClient = avatar;

// SendTextAsync should throw NotSupportedException (Simli is audio-only)
Func<Task> sendText = () => avatar.SendTextAsync("test");

// ConnectAsync only returns after authenticated ICE/DTLS media establishment.

// Bootstrap Simli output with a short PCM16 silence chunk.
var silentAudio = new byte[6000];
await avatar.SendAudioAsync(silentAudio);

// Require actual authenticated media from the real provider.
using var mediaTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(15));
var audioFrame = await avatar.ReceiveAudioFramesAsync(mediaTimeout.Token).FirstAsync(mediaTimeout.Token);

var videoFrame = await avatar.ReceiveVideoFramesAsync(mediaTimeout.Token).FirstAsync(mediaTimeout.Token);