Flutter Voicebot UI Kit
enx_voice_bot lets a Flutter app place an outbound call to an EnableX Dialogs voice
bot and hold a live, two-way voice conversation with it on Android and iOS. Unlike the Chatbot
UI Kit, there is no chat-bubble style prebuilt screen to attach — a voice call has no
message list to render. Instead, the package gives you a single call-control client
(EnxVoiceClient) that handles the REST call session, the real-time Pipecat
WebSocket audio stream, microphone capture, and speaker playback for you, and reports
call/mute/speaking state back through a listener so your app can drive a minimal call screen
(connect button, mute toggle, speaking indicators) with whatever widgets you want.
This guide documents v1.0.6+7, which moved call setup to REST call control and changed connect(). First released January 21, 2026 (v1.0.0). See Release Notes for the full version history.
Agent configuration — the LLM, speech-to-text, text-to-speech, and any RAG knowledge sources — is managed in the EnableX Dialogs console, not in the app. The SDK only connects your app's microphone and speaker to the voice bot behind a virtual number.
How It Works
A call passes through four layers. Your app only talks to the first one:
- Your Flutter app — creates an
EnxVoiceClient, gives it the virtual number to dial, and listens for events. - EnableX Voice Bot SDK (
enx_voice_bot) — requests the microphone permission, starts the call through the EnableX Voice Agent REST API, and opens the media WebSocket. - EnableX media gateway — carries the call audio between the device and the bot over WebSocket, using Pipecat protobuf frames.
- AI agent — the voice bot configured in Dialogs: speech-to-text, the LLM, and text-to-speech.
The SDK takes care of audio capture, streaming, and the call session lifecycle, so your code deals only with when to start and end the call and how to show its state.
Typical use cases
- In-app customer support voice assistant
- Hospital or clinic appointment booking bot
- Sales or lead-qualification voice agent inside an e-commerce app
- Banking voice verification assistant
- Educational tutor voice bot
Requirements
| Requirement | Version |
|---|---|
| Flutter | 3.16.0 or later |
| Dart SDK | 3.9.2 or later (sdk: ^3.9.2) |
| Android | API level 24 (Android 7.0) or later |
| iOS deployment target | 12.0 or later (CocoaPods or Swift Package Manager) |
| Test device | A physical Android or iOS device — simulators and emulators do not provide microphone access |
| Virtual number & voice bot config | Provided by your EnableX account / dialog setup |
Installation
Add the package
flutter pub add enx_voice_bot
This adds the dependency to your pubspec.yaml:
dependencies:
enx_voice_bot: ^1.0.6+7
The package brings in its own runtime dependencies — including permission_handler (microphone permission), record and flutter_sound (audio capture and playback), web_socket_channel (media stream), and protobuf (Pipecat frames). They are resolved automatically by flutter pub get; no separate install step is needed.
Import the libraries
One import gives you the whole public API:
import 'package:enx_voice_bot/enx_voice.dart';
enx_voice.dart re-exports the three other public libraries, which you can also import individually: enx_voice_client.dart (EnxVoiceClient), enx_voice_listener.dart (EnxVoiceListener), and enx_voice_state.dart (EnxVoiceState).
Platform setup
- Android — no manual linking is required; the Flutter plugin registers itself. Add the manifest permissions in Required Permissions.
- iOS — add the microphone usage description to
Info.plist(see Required Permissions), then run the app once so Flutter installs the iOS plugin.
Required Permissions MANDATORY
The SDK requests microphone access at runtime before every call, but the underlying platform permission must be declared by the host app.
Android — AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
| Permission | Purpose |
|---|---|
INTERNET | Required for the REST call and WebSocket media connection. |
RECORD_AUDIO | Required to capture microphone audio. |
MODIFY_AUDIO_SETTINGS | Required to route call audio through the speaker / communication device. |
iOS — Info.plist
Add Privacy – Microphone Usage Description, with a short explanation as its value:
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access to talk to the voice bot.</string>
iOS shows this text to the user the first time the app requests microphone access; without this key the app cannot get microphone access and the call cannot start.
Runtime permission flow
When EnxVoiceClient.connect() is called, the SDK checks the microphone permission and requests it if it has not been granted yet. If the user denies the permission, connect() stops, the listener's onError() callback receives an error message, and no call is placed.
Configuration
Use EnxSdkConfig to choose which EnableX environment the SDK talks to. If you do not set one, the client uses QA.
| Configuration | Base URL | Logging |
|---|---|---|
EnxSdkConfig.qa | https://voiceagent-qa.enablex.io | Enabled (verbose) |
EnxSdkConfig.production | https://voiceagent.enablex.io | Disabled |
To choose the logging behavior explicitly, build a config from one of the environment presets:
import 'package:enx_voice_bot/enx_voice.dart';
final config = EnxSdkConfig.fromEnvironment(
EnxVoiceEnvironment.production,
enableLogging: false,
);
You can also override the call API base URL for a single call without changing the SDK config, by passing callApiBaseUrl to connect() — see Connect and disconnect.
Call setSdkConfig(EnxSdkConfig.production) before connect() in release builds. The QA default points at the EnableX QA environment and logs verbosely.
Integration Steps
- Add the package with
flutter pub add enx_voice_bot(see Installation above). - Add the Android manifest permissions and the iOS Info.plist microphone usage description (see Required Permissions above).
- Implement
EnxVoiceListenerto receive call, mute, error, and speaking-state callbacks — see the Usage Example. - Create an
EnxVoiceClient, call.init(virtualNumber),.setEnxVoiceListener(...), and.setSdkConfig(EnxSdkConfig.qa or .production). - Call
connect()to start a call anddisconnect()to end it; usemuteAudio()andsendDtmf()as needed during the call. - Switch to
EnxSdkConfig.production(orfromEnvironmentwithenableLogging: false) before release builds to disable verbose SDK logging. - Test on real Android and iOS devices — see Developer Troubleshooting if a call fails to connect.
Library Exports
| Library | Exports |
|---|---|
package:enx_voice_bot/enx_voice.dart | EnxSdkConfig — class; SDK environment/logging configuration.EnxVoiceEnvironment — enum; REST base URL presets (QA, Production).Plus everything from the three libraries below (re-exported). |
package:enx_voice_bot/enx_voice_client.dart | EnxVoiceClient — class; main entry point for placing and controlling a voice bot call. |
package:enx_voice_bot/enx_voice_listener.dart | EnxVoiceListener — abstract class; callbacks for call/audio events. |
package:enx_voice_bot/enx_voice_state.dart | EnxVoiceState — enum; call connection states. |
EnxVoiceClient class
Controls the lifecycle of a single outbound voice bot call: requesting permissions, starting the call through the REST API, opening the Pipecat WebSocket, and streaming audio.
Constructor
EnxVoiceClient()
Creates a new client with its own audio player and recorder. Each instance manages at most one call at a time.
Configuration methods
EnxVoiceClient setSdkConfig(EnxSdkConfig config)
Sets the environment (QA/Production/custom) and logging behavior used for subsequent connect() calls. Defaults to QA if never called. Returns the client for chaining.
EnxVoiceClient init(String virtualNumber)
Sets the virtual number (E.164 format) that will be dialed when connect() is called. Returns the client for chaining.
EnxVoiceClient setEnxVoiceListener(EnxVoiceListener listener)
Registers the listener that receives call, mute, error, and speaking-state callbacks. Returns the client for chaining.
EnxVoiceClient setOnDtmfKeypadChanged(void Function(bool showKeypad)? callback)
Registers a callback invoked when the active call session reports whether DTMF keypad input is available: once when the call starts (with the dtmf flag from POST /v2token), and with false when the call ends. Pass null to remove it. Returns the client for chaining. The same callback is also exposed as the read/write property onDtmfKeypadChanged.
Call control methods
Future<void> connect({String? callApiBaseUrl})
Starts a call: verifies/requests the microphone permission, initializes the audio components, calls POST /v2token, and opens the WebSocket media session. If callApiBaseUrl is omitted, the URL from the configured EnxSdkConfig environment is used. Emits onStatus(EnxVoiceState.connecting) then either onStatus(EnxVoiceState.connected) or onStatus(EnxVoiceState.failed) via the listener. Calling it again while a call is already connecting is ignored.
Future<void> disconnect()
Ends the active call: deletes the REST call session (DELETE /v2token/{voiceId}, only if the call was successfully started), closes the WebSocket, stops audio capture/playback, and resets internal state. Emits onCallDisconnect(); onStatus(EnxVoiceState.disconnected) is reported when the media WebSocket closes. Errors during cleanup are logged, not thrown.
Future<bool> muteAudio(bool isMute)
Mutes or unmutes the microphone. Returns true on success, false if an error occurred. Emits onMuteStateChanged() on success.
bool isMuted()
Returns the current microphone mute state.
Future<bool> sendDtmf(String digits)
Sends DTMF digits (0–9, *, #) to the active call session. The input is trimmed first. Returns false if there is no active session, the input is empty, or it contains invalid characters.
Read-only properties
| Property | Type | Description |
|---|---|---|
activeVoiceId | String? | The voice session ID returned by the REST API for the current call, if any. |
hasCallApiBaseUrl | bool | Whether a non-empty call API base URL is currently set. |
isConnectingOrConnected | bool | True while a call is being established or is active. |
hasNotifiedDisconnect | bool | True once onCallDisconnect() has been delivered for the current/last call. |
EnxVoiceListener abstract class
Implement this class (typically on your call screen's State) and pass it to setEnxVoiceListener() to receive call events.
| Method | Called when… |
|---|---|
void onCallConnected() | The WebSocket media session has successfully opened. |
void onCallDisconnect() | The call has fully ended (user-initiated or by the remote side/error). Fires at most once per call. |
void onError(String message) | A recoverable or fatal error occurs (permission denial, REST failure, WebSocket error, etc.). |
void onMuteStateChanged(bool isMuted) | The microphone mute state changes as a result of muteAudio(). |
void onStatus(EnxVoiceState state) | The overall call state transitions (see EnxVoiceState below). |
void onUserSpeaking(bool isUserSpeaking) | The bot's voice-activity detector reports the user started/stopped speaking. |
void onBotSpeaking(bool isBotSpeaking) | The bot starts or stops producing spoken audio. |
EnxVoiceState enum
| Value | Description |
|---|---|
connecting | Permissions are being verified and the call is being initiated. |
connected | The media WebSocket is open and audio can flow. |
disconnected | No active call. This is also the initial state before connect() is called. |
failed | The call failed to establish or was terminated due to an error. |
EnxSdkConfig class
Holds the REST environment and logging preference used by EnxVoiceClient.
Constants
| Member | Environment | Logging |
|---|---|---|
EnxSdkConfig.qa | https://voiceagent-qa.enablex.io | Enabled |
EnxSdkConfig.production | https://voiceagent.enablex.io | Disabled |
Factory constructor
factory EnxSdkConfig.fromEnvironment(
EnxVoiceEnvironment environment, {
bool? enableLogging,
})
Builds a config from an environment preset. If enableLogging is omitted, logging defaults to disabled for EnxVoiceEnvironment.production and enabled otherwise.
Instance members
| Member | Type | Description |
|---|---|---|
environment | EnxVoiceEnvironment | The REST environment this config points to. |
enableLogging | bool | Whether the SDK emits verbose debug logs. |
toString() | String | Human-readable summary, e.g. "EnxSdkConfig(environment: QA, logging: true)". |
EnxVoiceEnvironment enum
| Value | name | callApiBaseUrl |
|---|---|---|
qa | QA | https://voiceagent-qa.enablex.io |
production | Production | https://voiceagent.enablex.io |
callApiBaseUrl is the base URL (no trailing slash) for the Voice Agent REST endpoints the client calls to start, end, and send DTMF to a call. Because EnxVoiceEnvironment is an enum, a custom deployment is targeted per call by passing callApiBaseUrl to connect(), rather than by defining a new environment.
Low-Level Helpers advanced
Exposed for custom integrations and testing; most applications should let EnxVoiceClient manage the microphone stream instead of calling it directly.
| Method | Description |
|---|---|
void sendAudio(AudioRawFrame audio) | Wraps a raw audio frame in a Pipecat frame and sends it over the active media WebSocket as binary. |
AudioRawFrame is the generated Pipecat protobuf class. It is not re-exported by the package's public libraries, so calling sendAudio() means importing the package's internal (src/) code, which can change between versions.
REST API Reference
EnxVoiceClient calls the following EnableX Voice Agent REST endpoints internally. They are documented here for troubleshooting and for advanced integrations that need to call them directly. {callApiBaseUrl} is the environment base URL (for example https://voiceagent.enablex.io); a trailing slash is stripped.
Start a call
POST {callApiBaseUrl}/v2token
Content-Type: application/json
Request body — the virtual number passed to init():
{
"phone": "<virtual number, E.164>"
}
On success, returns HTTP 200 with a JSON body containing voice_id (or
voiceId), a WebSocket URL (the first non-empty of wss_host,
wss_url, wssUrl, pipecat_url, pipecatUrl,
url, ws_url), and an optional dtmf flag. If the body
carries a statusCode (or status_code) other than 200, or the voice ID
or WebSocket URL is missing, the call is treated as failed.
Some deployments return this payload base64-encoded inside a top-level "data" field; the SDK decodes it automatically.
Used by EnxVoiceClient.connect().
End a call
DELETE {callApiBaseUrl}/v2token/{voiceId}
Returns HTTP 200 on success. Used by EnxVoiceClient.disconnect() (only if the call was successfully started).
Send DTMF digits
POST {callApiBaseUrl}/v2token/{voiceId}/dtmf
Content-Type: application/json
Request body:
{
"digits": "<0-9, *, #>"
}
Returns HTTP 200 on success. Used by EnxVoiceClient.sendDtmf(digits).
Media WebSocket
After POST /v2token succeeds, the SDK opens a WebSocket connection to the returned
URL, sending the voice ID in an X-Voice-Id header, and exchanges binary,
protobuf-framed Pipecat messages: outgoing 16 kHz mono PCM microphone audio frames, and
incoming bot audio frames plus JSON control events such as bot-started-speaking,
bot-stopped-speaking, user-started-speaking, and
user-stopped-speaking.
Some doc comments in the package source still describe these endpoints as /call; the requests the SDK actually sends use /v2token, as shown above.
Usage Example
Implement the listener
Your call screen implements EnxVoiceListener to receive call state, speaking state, mute state, and error events, and calls setState to refresh the UI.
import 'package:flutter/material.dart';
import 'package:enx_voice_bot/enx_voice.dart';
class VoiceBotScreen extends StatefulWidget {
const VoiceBotScreen({super.key});
@override
State<VoiceBotScreen> createState() => _VoiceBotScreenState();
}
class _VoiceBotScreenState extends State<VoiceBotScreen>
implements EnxVoiceListener {
late final EnxVoiceClient _client;
EnxVoiceState _state = EnxVoiceState.disconnected;
bool _muted = false;
bool _botSpeaking = false;
bool _userSpeaking = false;
bool _showKeypad = false;
@override
void onCallConnected() { /* call is live */ }
@override
void onCallDisconnect() { /* call ended */ }
@override
void onError(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
}
@override
void onMuteStateChanged(bool isMuted) => setState(() => _muted = isMuted);
@override
void onStatus(EnxVoiceState state) => setState(() => _state = state);
@override
void onUserSpeaking(bool isUserSpeaking) =>
setState(() => _userSpeaking = isUserSpeaking);
@override
void onBotSpeaking(bool isBotSpeaking) =>
setState(() => _botSpeaking = isBotSpeaking);
// build() renders a connect button, a mute toggle and speaking indicators
// from _state, _muted, _userSpeaking and _botSpeaking.
}
Create and configure the client
@override
void initState() {
super.initState();
_client = EnxVoiceClient()
.init('911100123457') // virtual number to dial
.setEnxVoiceListener(this)
.setSdkConfig(EnxSdkConfig.qa); // or EnxSdkConfig.production
}
Connect and disconnect
// Start a call
await _client.connect();
// Optionally override the REST base URL for this call only
await _client.connect(callApiBaseUrl: 'https://voiceagent.enablex.io');
// End the call
await _client.disconnect();
End the call when the screen goes away, so the microphone and WebSocket are released:
@override
void dispose() {
if (_client.isConnectingOrConnected) {
_client.disconnect();
}
super.dispose();
}
Mute and unmute the microphone
await _client.muteAudio(true); // mute
await _client.muteAudio(false); // unmute
_client.isMuted(); // current mute state
Send DTMF digits
When the call starts, the callback registered with setOnDtmfKeypadChanged is told whether the bot session supports a DTMF keypad, so your app can show or hide one. It is called with false again when the call ends:
_client.setOnDtmfKeypadChanged((showKeypad) {
setState(() => _showKeypad = showKeypad);
});
Digits are sent with:
final sent = await _client.sendDtmf('123#');
sendDtmf() accepts digits 0–9, * and #, and returns false if there is no active call session or the input is invalid.
React to speaking state
While a call is active, onUserSpeaking(true/false) and
onBotSpeaking(true/false) fire as the bot's voice-activity detector toggles. Use
them to animate “listening” and “speaking” indicators on your call
screen. The SDK automatically pauses microphone upload while the bot is speaking and resumes
it shortly after the bot stops, to avoid echo/overlap.
Feature Support (v1.0.6+7)
| Feature | Supported | Notes |
|---|---|---|
| Outbound voice bot calling | Yes | Single REST call (POST /v2token) returns a voice session ID and a WebSocket URL. |
| Real-time full-duplex audio | Yes | WebSocket streaming using Pipecat protobuf frames (16 kHz mono microphone upload, bot audio playback). |
| Android and iOS | Yes | One Dart API for both platforms. |
| Automatic permission handling | Yes | Microphone permission requested/verified automatically before a call starts. |
| Mute / unmute | Yes | muteAudio() / isMuted() during an active call. |
| DTMF digit sending | Yes | For calls where the bot indicates a keypad is available. |
| Speaking-state callbacks | Yes | onUserSpeaking / onBotSpeaking so the host app can show speaking indicators. |
| Selectable environments | Yes | Built-in QA and Production via EnxSdkConfig; per-call base URL override via connect(callApiBaseUrl: ...). |
| Prebuilt call UI (screens/widgets) | No | The package is a headless call-control client — your app builds its own call screen from the listener callbacks. |
| Inbound call handling | No | The SDK only initiates outbound calls to a virtual number. |
| Multiple concurrent calls | No | One active call per EnxVoiceClient instance; create a new instance (or fully disconnect) before starting another call. |
Known Issues & Limitations
- Outbound calls only — the SDK initiates calls to a virtual number; there is no inbound call handling.
- One active call per
EnxVoiceClientinstance — create a new instance (or fully disconnect) before starting another call. - Physical device required — simulators and emulators do not provide microphone access.
- DTMF sending requires the bot session to report keypad support; otherwise
sendDtmf()returnsfalse. - Verbose debug logging is enabled by default under the QA configuration (which is also the default when no config is set); use
EnxSdkConfig.productionorenableLogging: falsefor release builds.
Developer Troubleshooting
| Symptom | Likely cause / fix |
|---|---|
connect() fails immediately with a permission error | Microphone permission was denied, or the Info.plist key / manifest permission is missing. Prompt the user to enable it in system settings. |
| “callApiBaseUrl is not set” error | The configured environment has no base URL and none was passed to connect(). Call setSdkConfig() or pass callApiBaseUrl explicitly. |
| No microphone audio on a simulator or emulator | Expected — test on a physical device. |
| No audio heard on Android | Confirm MODIFY_AUDIO_SETTINGS is declared and the device is not in silent/Do-Not-Disturb mode with media muted. |
sendDtmf() always returns false | There is no active call, or the bot session did not enable DTMF for this call. |
| Call connects but disconnects immediately | Check onError() output and server-side logs; the WebSocket endpoint returned an error or closed the session. |
Upgrade Notes
- Upgrading from v1.0.6+6 or earlier is a breaking change.
connect(token, options)becameconnect({callApiBaseUrl}), the app no longer fetches a token, and the default environment is now QA. Follow Migrating from v1.0.6+6 or earlier. - After bumping the package version, run
flutter pub getand do a full rebuild (not a hot restart), since the package ships native Android and iOS plugin code. - Review
EnxSdkConfigusage before release builds — useEnxSdkConfig.production(orfromEnvironmentwithenableLogging: false) to disable verbose SDK logging.
Resources
- enx_voice_bot on pub.dev
- Sample app on GitHub
- Dialogs Voice Bots — building and configuring the voice bot this SDK calls