Installing
Addavatar_kit to your package’s pubspec.yaml and run flutter pub get
Copy
dependencies:
avatar_kit: ^1.0.0-beta.13
Platform Setup
- iOS
- Android
Ensure your iOS deployment target is 16.0+ and run
cd ios && pod installEnsure your
android/app/build.gradle has minSdkVersion 24+:Copy
android {
defaultConfig {
minSdkVersion 24
}
}
Usage
- SDK Driving Service Mode
- Host Driving Service Mode
Obtain app ID and temporary session token from Open Platform
1
Initialize SDK
Copy
import 'package:avatar_kit/avatar_kit.dart';
AvatarSDK.initialize(
appID: 'your_app_id',
configuration: Configuration(
environment: Environment.intl,
audioFormat: AudioFormat(sampleRate: 16000),
drivingServiceMode: DrivingServiceMode.sdk,
logLevel: LogLevel.off,
),
);
2
Provide Session Token
Copy
AvatarSDK.setSessionToken('your_session_token');
3
Load Avatar
Copy
try {
final avatar = await AvatarManager.shared.load(id: 'your_avatar_id', onProgress: (progress) {});
} on AvatarError catch (e) {
// handle AvatarError
} catch (e) {
// handle error
}
4
Create Avatar Widget
Copy
AvatarWidget(
avatar: avatar,
onPlatformViewCreated: (controller) {
// avatarController = controller;
},
)
5
Register Callbacks
Copy
avatarController.onFirstRendering = () {};
avatarController.onConnectionState = (state, errorMessage) {};
avatarController.onConversationState = (state) {};
avatarController.onError = (error) {};
6
Drive Avatar
Copy
// Start avatar service connection
avatarController.start();
// Trigger new conversation by sending audio data stream
avatarController.send(audioData1, end: false);
avatarController.send(audioData2, end: true);
// Interrupt current conversation
avatarController.interrupt();
// Close avatar service connection
avatarController.close();
Obtain app ID from Open Platform
1
Initialize SDK
Copy
import 'package:avatar_kit/avatar_kit.dart';
AvatarSDK.initialize(
appID: 'your_app_id',
configuration: Configuration(
environment: Environment.intl,
audioFormat: AudioFormat(sampleRate: 16000),
drivingServiceMode: DrivingServiceMode.host,
logLevel: LogLevel.off,
),
);
2
Load Avatar
Copy
try {
final avatar = await AvatarManager.shared.load(id: 'your_avatar_id', onProgress: (progress) {});
} on AvatarError catch (e) {
// handle AvatarError
} catch (e) {
// handle error
}
3
Create Avatar Widget
Copy
AvatarWidget(
avatar: avatar,
onPlatformViewCreated: (controller) {
// avatarController = controller;
},
)
4
Register Callbacks
Copy
avatarController.onFirstRendering = () {};
avatarController.onConversationState = (state) {};
avatarController.onError = (error) {};
5
Drive Avatar
Copy
// Trigger new conversation by yielding audio data stream
final conversationID = avatarController.yieldAudioData(audioData1, end: false);
avatarController.yield(audioData2, end: true);
// Yield animation data list from the server SDK integration
avatarController.yieldAnimations(animations1, conversationID: conversationID);
avatarController.yieldAnimations(animations2, conversationID: conversationID);
// Interrupt current conversation
avatarController.interrupt();

