When to use Flutter Edge Ai Speech
Flutter Edge Ai Speech brings high‑performance, offline speech capabilities directly into your Flutter applications. By leveraging the lightweight LiteRT C library through dart:ffi, the package provides both Speech‑to‑Text (STT) and Text‑to‑Speech (TTS) without any network dependency. This means you can deliver instant voice interaction, preserve user privacy, and operate in environments with limited or no internet connectivity. The API is deliberately minimal: you opt‑in to a backend provider for STT, TTS, or both, and then call simple methods to start transcription or synthesize audio.
The package shines in scenarios where latency and data security are paramount. Voice assistants, hands‑free controls, and accessibility tools benefit from the sub‑second response time that on‑device processing offers. Because the heavy lifting happens in native code, the Dart side remains lightweight, allowing you to keep your UI smooth even while processing long audio streams. The design also fits cleanly into common Flutter architectures—whether you use Provider, Bloc, Riverpod, or any other state‑management solution—by exposing streams and change‑notifiers that can be consumed anywhere in the widget tree.
Integrating Flutter Edge Ai Speech is straightforward. After adding the dependency, you must include the native LiteRT binaries for each target platform and declare the required microphone and speaker permissions. The package abstracts the platform‑specific details, exposing a unified `EdgeSpeech` class that you can initialise in your `main()` or within a dedicated service layer. Once initialised, you can start an STT session with `startListening()` and receive real‑time transcription via a `Stream<String>`. For TTS, simply call `speak('Your text')` and the library handles audio playback using the device’s native audio pipeline. The entire flow can be wrapped in a Provider or Bloc to keep UI code declarative and testable.
When moving to production, consider a few practical cautions. The LiteRT engine ships with a set of language models that cover the most common languages, but the package does not automatically download additional models; you’ll need to bundle them or provide a custom model loader. Native library size can add several megabytes to your app bundle, so evaluate the impact on download size, especially for mobile markets with strict limits. Additionally, while the API is designed for low latency, extremely long recordings may still consume noticeable CPU, so you may want to implement a timeout or chunking strategy for continuous dictation use cases. Finally, always test on the actual device hardware you target, as performance can vary between ARM and x86 architectures.
For developers new to on‑device speech, Flutter Edge Ai Speech offers a gentle learning curve. The example app included in the package demonstrates a single screen with a microphone button that starts transcription, displays the recognized text, and provides a text field to trigger TTS. By following that pattern, you can quickly prototype voice‑driven features and then scale them into larger applications. Whether you are building a multilingual chatbot, an accessibility overlay, or a hands‑free IoT controller, this package gives you the building blocks to add robust speech interaction without relying on cloud services.
Pros
- offline operation preserves privacy
- low latency due to native processing
- single API for both STT and TTS
- compatible with common state‑management solutions
Watch outs
- adds native library size to app bundle
- limited language model set out‑of‑the‑box
- requires platform‑specific permission handling
- no real‑time streaming support yet
Setup notes
1. Run `flutter pub add flutter_edge_ai_speech`. 2. Execute `flutter pub get` to fetch the package. 3. Add the LiteRT native libraries to `android/app/src/main/jniLibs`, `ios/Runner`, and other platform folders as described in the README. 4. Declare microphone and audio permissions in `AndroidManifest.xml` and `Info.plist`. 5. Initialise the provider in your app start‑up, e.g., `await EdgeSpeech.instance.initialize();`. 6. Follow the platform‑specific post‑install steps for iOS (pod install) and Android (gradle sync).
Supported on Android API 21+, iOS 12+, macOS 10.14+, Linux desktop, and Windows. Requires Flutter 3.0+ and Dart 2.17+. Works on arm64 and x86_64 architectures. The package uses dart:ffi, so it is not compatible with web targets.
import 'package:flutter/material.dart';
import 'package:flutter_edge_ai_speech/flutter_edge_ai_speech.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EdgeSpeech.instance.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
home: const SpeechDemo(),
);
}
class SpeechDemo extends StatefulWidget {
const SpeechDemo({Key? key}) : super(key: key);
@override
State<SpeechDemo> createState() => _SpeechDemoState();
}
class _SpeechDemoState extends State<SpeechDemo> {
final _controller = TextEditingController();
String _transcript = '';
StreamSubscription<String>? _sub;
@override
void dispose() {
_sub?.cancel();
super.dispose();
}
void _startListening() {
_sub = EdgeSpeech.instance.sttStream.listen((text) {
setState(() => _transcript = text);
});
EdgeSpeech.instance.startListening();
}
void _stopListening() => EdgeSpeech.instance.stopListening();
void _speak() => EdgeSpeech.instance.speak(_controller.text);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Edge AI Speech Demo')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
ElevatedButton(
onPressed: _startListening,
child: const Text('Start Listening'),
),
ElevatedButton(
onPressed: _stopListening,
child: const Text('Stop Listening'),
),
Text('Transcript: $_transcript'),
TextField(controller: _controller, decoration: const InputDecoration(labelText: 'Text to speak')),
ElevatedButton(onPressed: _speak, child: const Text('Speak')),
],
),
),
);
}