🎉 New Feature Available! Video interaction with streaming avatars is now live! You can now enable two-way video communication with your avatars, including camera switching capabilities and video quality controls. Check out the Video Interaction section for implementation details.
Overview
The Streaming Avatar feature allows you to create interactive, real-time avatar experiences in your application. This guide provides a comprehensive walkthrough of integrating streaming avatars using the Agora SDK, including:- Setting up real-time communication channels
- Handling avatar interactions and responses
- Managing audio streams
- Implementing cleanup procedures
- Optional LLM service integration
Prerequisites
- Install the Agora SDK in your project:
- Import the required dependencies:
- Add the hidden API of Agora SDK
sendStreamMessage
method needs to be manually added to the type definitions:
Important: The Agora SDK has the following limitations:
- Maximum message size: 1KB
- Maximum message frequency: 6KB per second
Integration Flow
Key Implementation Steps
1. Create a Live Avatar Session
Security Recommendation: We strongly recommend implementing session management through your backend server rather than directly in the browser. This approach:
- Protects your AKool API token from exposure
- Allows for proper request validation and rate limiting
- Enables usage tracking and monitoring
- Provides better control over session lifecycle
- Prevents unauthorized access to the API
2. Initialize Agora Client
Create and configure the Agora client:3. Subscribe Audio and Video Stream
Subscribe to the audio and video stream of the avatar:4. Set Up Message Handling
Configure message listeners to handle avatar responses:5. Send Messages to Avatar
Implement functions to interact with the avatar:6. Control Avatar Parameters
Implement functions to control avatar settings:7. Audio Interaction With The Avatar
To enable audio interaction with the avatar, you’ll need to publish your local audio stream:8. Video Interaction With The Avatar
To enable video interaction with the avatar, you’ll need to publish your local video stream:- Two-way video communication
- Camera switching capabilities
- Video quality controls
- Integration with existing audio features
9. Integrating your own LLM service (optional)
You can integrate your own LLM service to process messages before sending them to the avatar. Here’s how to do it:Remember to:
- Implement proper rate limiting for your LLM service
- Handle token limits appropriately
- Implement retry logic for failed LLM requests
- Consider implementing streaming responses if your LLM service supports it
- Cache common responses when appropriate
10. Cleanup
Cleanup can also be performed either directly or through your backend:When implementing through your backend, make sure to:
- Securely store your AKool API token
- Implement proper authentication and rate limiting
- Handle errors appropriately
- Consider implementing session management and monitoring