Install
Quick start
Region configuration
The SDK defaults tous-west when no region is provided, or when WithRegion receives an empty or whitespace-only value. See Regions for the current region list. To set a region:
Session lifecycle
- Create a session with
NewAvatarSession. - Call
Init(ctx)to exchange the API key and expiry time for a session token. - Call
Start(ctx)to open the ingress WebSocket and configure the avatar session. - Call
SendAudio(audio, end)for each audio chunk. - Call
Interrupt()when playback should stop. - Call
Close()when the session is done.
SendAudio returns the request ID associated with the audio. The callback passed to WithTransportFrames receives motion data payloads and a last flag.
For audio source and timing guidance, see Audio.
Audio format
PCM 16-bit little-endian is the default input format:nil to WithOggOpusEncoder enables the default encoder config.
Authentication mode
By default, WebSocket authentication is sent in headers:LiveKit egress
Use LiveKit egress when Spatius should publish avatar output directly into a LiveKit room:APIToken for new integrations. APIKey and APISecret remain available for older setups.
Options
Core options:WithAPIKey(apiKey string)- Console API key.WithAppID(appID string)- application ID.WithAvatarID(avatarID string)- avatar ID.WithExpireAt(expireAt time.Time)- session token expiry.WithRegion(region string)- region used to select the Spatius region. Empty or whitespace-only values fall back tous-west.WithConsoleEndpointURL(endpointURL string)- explicit Console API URL.WithIngressEndpointURL(endpointURL string)- explicit ingress WebSocket URL.
WithSampleRate(sampleRate int)- input sample rate in Hz.WithBitrate(bitrate int)- target bitrate for encoded sessions.WithAudioFormat(audioFormat AudioFormat)-AudioFormatPCMS16LEorAudioFormatOggOpus.WithOggOpusEncoder(config *OggOpusEncoderConfig)- enable client-side PCM to Ogg Opus encoding.
WithTransportFrames(func([]byte, bool))- receives motion data payloads.WithOnEncodedAudio(func(string, []byte))- receives internally encoded audio by request ID.WithOnError(func(error))- receives async session errors.WithOnClose(func())- runs when the session closes.
WithLiveKitEgress(config *LiveKitEgressConfig)- stream output to LiveKit.WithAgoraEgress(config *AgoraEgressConfig)- stream output to Agora.

