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
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");

// Send a short PCM16 audio chunk (silence)
var silentAudio = new byte[3200]; // 100ms of silence at 16kHz mono PCM16
await avatar.SendAudioAsync(silentAudio);

// The connection should be established
// Note: IsConnected checks both WebSocket and WebRTC state
// WebRTC may take a moment to establish