‹ Platforms
Build a Flutter app
Stream audio into a Flutter avatar and show its frames in your app.
Integrate into your app
The avatar is a Texture in your widget tree. On Android the first argument to load is the agent code:
// excerpt: app/avatar_chat/lib/main.dart (bithuman-examples)
import 'package:bithuman/bithuman.dart';
await BithumanAvatar.setExpression2AgentDir('A23WJF0199');
final avatar = await BithumanAvatar.load('A23WJF0199', engine: 'expression2', apiSecret: secret);
Texture(textureId: avatar.textureId); // the avatar in your layout
avatar.pushAudio(pcm); // Int16List, 16 kHz mono speech
avatar.interrupt(); // cut the current reply
await avatar.dispose(); // release the engine
| Job | Call |
|---|---|
| Show the avatar | Texture(textureId:; frameWidth and frameHeight give its size |
| Stream speech | pushAudio(Int16List), 16 kHz mono |
| Know it is ready | isReady; audio pushed before it is dropped |
| Interrupt the reply | interrupt() |
| Stop | dispose() |
| Pick the model | engine: or engine: |
Complete example
The avatar_chat app is a complete voice conversation with idle motion and interruption, in one layout for every platform. From plugin 2.6.20 its voice session connects through bitHuman’s realtime relay with your API secret; no token is minted.
Platform notes
- Two models in one app:
essence2-androidneedsminSdk 29; raise the app to 29. - Your own voice pipeline: any speech your stack produces works, as 16 kHz mono PCM through
pushAudio. - Captions: with the plugin’s realtime session, show
spokenTranscriptStreamrather thanbotTranscriptStream. It releases the agent’s words as they are heard, so the caption keeps pace with the voice; each event holds the reply’s caption so far, and a cut reply ends with only the words heard (plugin 2.6.27 or newer). - iOS (16+) and macOS (13+, Apple silicon) builds: run the plugin’s
scripts/bootstrap.shonce (it downloads the published engines and checks their sha256; for a git dependency the plugin’s folder ispackages/flutter-pluginunder~/.pub-cache/git/homebrew-bithuman-…), raise the deployment targets (platform :ios, '16.0'inios/Podfile,platform :osx, '13.0'inmacos/Podfile, and the Runner targets to match), and on macOS runbrew install llama.cpp onnxruntime, which the plugin links. - Versions: each plugin tag fixes the Android SDK versions it uses. The current tag and its line are on Downloads & versions.
Reference
- Android: the engines under the plugin, their API and their settings.
avatar_chatexample and the plugin source.- Changelog and Downloads & versions.