Skip to main content
This guide covers how to send avatar audio and animation to an Agora channel from your backend. Right now only the Server SDK path is available; a framework plugin is planned.

1. Using the TEN Framework (Coming Soon)

If you build your voice agent with TEN Framework (Token-Enabled Network) or a similar Agora-based agent framework, a Spatialreal plugin will let you plug the avatar into your pipeline without managing the Server SDK or egress config yourself. Coming soon. The plugin is not yet available. Use the Server SDK with Agora egress (section 2) until then.

2. Using the Server SDK with Agora Egress

Use the Spatialreal AvatarKit Server SDK with Agora egress to send avatar output to an Agora channel. Your server streams audio to the avatar service and passes Agora egress config; the service publishes audio and animation directly to the channel. In this setup:
  • Your server sends audio to the avatar service and passes Agora egress config (channel name, token, UID).
  • The avatar service streams audio + animation directly into the Agora channel (your server does not relay that data).
  • Clients join the channel and use @spatialwalk/avatarkit-rtc to render the avatar.
You keep control over when and how you send audio (and optional interrupt signals; see below), while transport and sync are handled by the service and the RTC client.

Configuration

FieldDescription
channel_nameAgora channel name to join
tokenAgora token for authentication (optional for testing)
uidPublisher UID in the channel

Golang Example

session := avatarsdkgo.NewAvatarSession(
	avatarsdkgo.WithAPIKey("your-api-key"),
	avatarsdkgo.WithAppID("your-app-id"),
	avatarsdkgo.WithAvatarID("your-avatar-id"),
	avatarsdkgo.WithConsoleEndpointURL("https://console.us-west.spatialwalk.cloud/v1/console"),
	avatarsdkgo.WithIngressEndpointURL("wss://api.us-west.spatialwalk.cloud/v2/driveningress"),
	avatarsdkgo.WithExpireAt(time.Now().Add(5 * time.Minute)),
	avatarsdkgo.WithAgoraEgress(&avatarsdkgo.AgoraEgressConfig{
		ChannelName: "your-channel-name",
		Token:       "agora-token",
		UID:         0, // use your UID
	}),
	avatarsdkgo.WithOnError(func(err error) {
		// handle error
	}),
	avatarsdkgo.WithOnClose(func() {
		// handle close
	}),
)

Python Example

from avatarkit import new_avatar_session, AgoraEgressConfig

session = new_avatar_session(
    api_key="your-api-key",
    app_id="your-app-id",
    avatar_id="your-avatar-id",
    expire_at=datetime.now(timezone.utc) + timedelta(minutes=5),
    console_endpoint_url="https://console.us-west.spatialwalk.cloud/v1/console",
    ingress_endpoint_url="https://api.us-west.spatialwalk.cloud/v2/driveningress",
    agora_egress=AgoraEgressConfig(
        channel_name="your-channel-name",
        token="agora-token",
        uid=0,  # use your UID
        publisher_id="avatar-publisher",  # can be any string, reserved for future use
    ),
    on_error=lambda err: print(f"Error: {err}"),
    on_close=lambda: print("Session closed"),
)
After the session is created with Agora egress, send audio as in normal Server SDK usage; the service will publish to the configured channel automatically.

Important Notes

When Agora egress is enabled:
  • The TransportFrames / transport_frames callback will not be invoked
  • Audio and animation data are published directly to the specified Agora channel
  • Your client must use the @spatialwalk/avatarkit-rtc package to render the avatar (standard video players won’t work). See Agora Client Guide for client setup.

Interrupt

You can interrupt ongoing audio processing (e.g. when the user asks a new question). The interrupt uses the most recent request ID, even after end=true was sent. Golang
// Send audio
requestID, err := session.SendAudio(audioData, true)

// Later, interrupt if needed
interruptedID, err := session.Interrupt()
Python
# Send audio
request_id = await session.send_audio(audio_data, end=True)

# Later, interrupt if needed
interrupted_id = await session.interrupt()

Summary

ApproachBest forWhere to go
TEN Framework + PluginVoice agents built on TEN FrameworkComing soon (section 1)
Server SDK + Agora egressCustom backends, any language with a Server SDK (Go, Python, etc.)This page, section 2
For client-side setup (joining the channel and rendering the avatar), see Agora client guide.