Introduction
The MascotBOT SDK provides a set of tools and components to integrate interactive mascots into your React applications. This documentation will guide you through the installation process and explain the main mechanisms and hooks available in the SDK.Installation
To install the MascotBOT SDK, you need to add the package to your project. You can do this using the following command:You’ll get the latest version of our SDK with integration examples once you subscribe to one of our plans
Setup
1. Import and Wrap with MascotProvider
To use the SDK, wrap your application with the MascotProvider component.
2. Create a Rive Instance
Use theuseRive hook to create a Rive instance. This instance will manage the animations and state machines for your mascot.
3. Use MascotClient
The MascotClient component connects your Rive instance with the MascotBOT SDK.
Hooks
useMascot
The useMascot hook provides access to the Rive instance and Rive component.
useMascotPlayback
The useMascotPlayback hook allows you to control the playback of animations and manage visemes.
Controlling Speaking State
By default, the mascot’sis_speaking state is automatically set to true while it’s speaking and set to false when it stops. You can control this behavior by passing options to the useMascotPlayback hook:
setSpeakingState option allows you to disable the automatic management of the is_speaking state, giving you manual control over when and how the speaking state is set.
useMascotSpeech
The useMascotSpeech hook provides advanced text-to-speech functionality with support for multiple TTS engines, queueing, and real-time audio streaming.
Handling Visemes and Audio Playback
To create a synchronized animation and audio experience, you can use theplayback.add method to add visemes. This can be done in various ways, such as fetching from a server, generating in real-time, or any other method suitable for your application.
Adding Visemes
Visemes are visual representations of phonemes. You can add them to the playback to synchronize with the audio.Adding Audio
For speech playback, you need to provide an audio source. This can be done by setting the audio source dynamically.WebGL2 Performance Benefits
The SDK now uses WebGL2 for better performance and rendering capabilities:- Better Performance: Hardware-accelerated rendering for smoother animations
- Enhanced Effects: Support for advanced visual effects and shaders
- Improved Memory Usage: More efficient handling of graphics resources
- Better Scaling: Better performance with complex animations and multiple mascots
Conclusion
The MascotBOT SDK offers a flexible and powerful way to integrate mascots into your React applications. By following the setup instructions and utilizing the provided hooks, you can create engaging and interactive experiences for your users. The enhanceduseMascotSpeech hook provides production-ready speech capabilities with support for multiple TTS providers, intelligent queueing, and real-time streaming. For more detailed examples and integration guides, please refer to the separate article on production and integration examples.