Installation
Add the Flutter package from pub.dev:Import
Initialize
Initialize AvatarKit once before loading avatars or creating an avatar view.DrivingServiceMode.direct for Direct Mode. Use DrivingServiceMode.backend when your Flutter app receives response audio and motion data from Backend Mode Client.
initialize fails fast when appID is missing, rather than returning silently. Get an App ID from app.spatius.ai.
Configuration
The audio format is not part of
Configuration. Set it per view with AvatarWidget(audioFormat:); see AudioFormat.
RenderQuality
RenderQuality.ultra is the default and highest-quality tier. Use high or standard only when you intentionally trade visual quality for lower rendering cost.
AudioFormat
Each avatar view has its own audio format, so two views in one app can run different sample rates. Pass it toAvatarWidget(audioFormat:) when you create the view; it defaults to 16 kHz PCM. The value is used when the native view is created, so changing the widget property afterwards has no effect. Use AvatarController.setAudioFormat to change it at runtime.
Audio that does not match the declared
inputAudioFormat is reported through AvatarController.onError as AvatarError.invalidAudioInput.
AudioFormat has value equality and converts with toJson() / AudioFormat.fromJson().
Change the audio format at runtime
Read the format in effect for a view withcontroller.audioFormat(). It returns the format after the SDK’s normalization, for example 48000 Hz for Opus input.
setAudioFormat({sampleRate, inputAudioFormat, opusBitrate, opusUplinkEnabled}) changes the format of a live view without tearing the SDK down. Every parameter is optional; null keeps the current value.
- Any change interrupts whatever is playing and, in Direct Mode, disconnects. Call
start()again and feed audio in the new format. - Switching
inputAudioFormattoAudioCodec.opuspins the sample rate at 48000. Switching back toAudioCodec.pcmkeeps the current rate unless you passsampleRatein the same call. - Accepted sample rates are 8000, 16000, 22050, 24000, 32000, 44100, and 48000. An unsupported rate, or a
sampleRatepaired with Opus input, is logged by the SDK and leaves the format unchanged.
Load an avatar
Render and control playback
The Flutter view creates anAvatarController when the platform view is ready. Keep that controller and use it for lifecycle, state, and audio operations.
Render over an Avatar Background
Download the optional 16:9 background from Spatius Studio, add it to your Flutter assets, and declare it inpubspec.yaml.
AvatarWidget in the same Stack, with the image first.
The per-call
audioFormat parameter of yieldAudioData is deprecated and ignored. The format comes from the view: AvatarWidget.audioFormat, or whatever setAudioFormat last applied. Drop the argument if you still pass it; it will be removed in a future release. The iOS and Android SDKs have already removed theirs.
