Quick start: Flutter
flutter pub add alkoveor in pubspec.yaml:
dependencies: alkove: ^0.1.0import 'package:alkove/alkove.dart';
final input = await AgentInput.start(const AgentOptions(utterances: true));input.events.listen((e) { switch (e) { case Utterance(:final pcm): ws.add(pcm); case TurnEnd(): ws.add('{"type":"reply"}'); case _: }});The plugin runs the native SDKs, ai.alkove:alkove on Android and the Alkove Swift package on iOS: the same models, the same microphone handling (Apple’s echo canceller on iOS, the raw microphone when the phone cannot keep up), the same outputs to the bit as the browser. Its surface is React Native’s, in Dart: the events come as a Stream of sealed classes, the errors as an AlkoveError with the same codes. Android and iOS only, no Flutter web; tested on Flutter 3.50.
Set up the app
Section titled “Set up the app”On Android, the plugin brings Alkove’s Maven repository (https://maven.alkove.ai) and the RECORD_AUDIO permission. The microphone permission is asked the first time an input starts; denied, start throws AlkoveError('mic.denied').
On iOS, say why the app uses the microphone:
<!-- ios/Runner/Info.plist --><key>NSMicrophoneUsageDescription</key><string>Your voice, kept on this device.</string>The plugin brings a Package.swift for Swift Package Manager and a podspec for CocoaPods: nothing more to set. The plugin embeds the iOS SDK itself: the app must not also depend on the Alkove Swift package, as Swift Package Manager refuses two packages that both bring AlkoveFFI.
A voice agent
Section titled “A voice agent”AgentInput.start takes the options of createAgentInput: voiceprint, output, near, lowPower, turn, onlyMyVoice, wake, langs, keepRecent and trace.
final input = await AgentInput.start(const AgentOptions(utterances: true));input.events.listen((e) => switch (e) { Utterance(:final pcm) => transcribe(pcm), // one phrase, 300 ms before the speech to its end TurnEnd() => agent.reply(), Interrupt() => player.stop(), _ => null, });
await input.farEndActive(true); // while the agent speaks, false afterawait input.listen(false); // mute: the phrase under way comes as SpeechCancelawait input.hold(); // hold to talk, until release()await input.close(); // the microphone and the models stop, events endseventsgives everything the input says, in order, from its start: listen to it once.audio: truestreams the continuous output asAudioevents (32 ms chunks by default,outputsets the format and rate),utterances: trueeach phrase’s PCM asUtterance: no audio crosses to Dart otherwise.input.setVoiceprint(...)changes the print on the running input: a print’s JSON, or a few seconds of the user alone at 16 kHz.- From the first
farEndActive()call, the input learns the user’s print while the user talks, never while the agent does: store it fromVoiceprintLearnedand pass it back asvoiceprintnext time. See your agent’s voice. wake: WakeWords(['Hey Nova'], lang: ['en'])hears wake words on the raw microphone: their wakes come asWakewith the word’saudio, and each one gives Focus the voice that said it. See the agent quick start.keepRecent: 20keeps the last 20 seconds, up to 600:await input.recent()gives them as a stereo WAV at 16 kHz, the microphone on the left and the output on the right;nullwithoutkeepRecent.await input.record(10)gives the next ten seconds;await input.stats()the speech heard and the noise removed so far.lowPower: trueruns Focus without its separator; unset, the SDK adapts to the device by itself (Diagfocus.mode).
input.status is starting, running, interrupted (a call or Siri took the microphone) or disposed, and input.mode says where the audio comes from; both follow their StatusChange and ModeChange events.
A wake word
Section titled “A wake word”final word = await Spot.compile('Hey Nova', lang: ['en']); // any typed word, no trainingfinal wake = await WakeListener.start(WakeOptions([word]));wake.events.listen((e) { if (e is Wake) startListening();});Store a compiled word with jsonEncode(word.toJson()) and give it back with Word.fromJson: no compile at the next launch. context: 'anywhere' hears the word in the middle of a sentence, 'both' everywhere; by default it is heard after a pause. voiceprint lets only the user wake it. word.warnings says when the word will misfire more or will not be read as written.
Commands and languages
Section titled “Commands and languages”final commands = await Spot.commands({ 'commands': [ {'id': 'timer', 'phrases': {'en': ['set a timer for {number} minutes'], 'fr': ['mets un minuteur de {number} minutes']}}, ],}, langs: ['en', 'fr']);await input.setCommands(commands);Each utterance that says a command gives a Command with its id, phrase and slots. With two languages or more, each utterance also gives its Language; langs: ['fr', 'en'] on an agent or a wake listener gives it with no word or command. See voice commands and languages.
The models
Section titled “The models”The inputs load the models they need the first time they start: from the app’s cache, else from Hugging Face at this version’s revision, each file checked by its sha256. To download them ahead, on a settings or onboarding screen:
await Alkove.preload(Usage.agent, langs: ['fr', 'en'], onProgress: (p) => setProgress(p.loaded / p.total));final offline = await Alkove.cached(Usage.wake, typedWords: true, langs: ['en']); // true: an input can start without networkA call or an agent brings Focus, Cue and Timbre, and with two langs or more Spot’s bottom and language head; wake: counts an agent’s wake words. A wake listener brings Spot, a model per language of its words: add voiceprint: true for its voiceprint, and typedWords: true for a word compiled from text.
Alkove.configure, before the first input, says where every model comes from:
await Alkove.configure(modelBaseUrl: 'https://example.com/alkove/'); // your own host, into the app's cacheawait Alkove.configure(modelBaseUrl: 'alkove'); // .alk files shipped in the app: nothing on the networkawait Alkove.configure(modelBaseUrl: folder); // a folder of .alk files on the deviceA relative path is a folder shipped in the app: android/app/src/main/assets/alkove on Android, a folder reference named alkove in the iOS app’s bundle.