blender-motion-state-inspection
AFaffaan-m/ECC315k近 7 天新增 4,381 个 star
Use when adding speech to a flutter_edge_ai app — speech-to-text (transcribe a voice note, dictation, Whisper, moonshine, Parakeet), text-to-speech (Matcha, Qwen3-TTS, Inflect), or a push-to-talk voice assistant with VoiceSession. Also use when transcripts come back in English for non-English audio, a WAV file has to become 16 kHz PCM, synthesized audio plays at the wrong pitch, or getActiveTts throws a StateError about the language. For audio sent straight to Gemma in a chat, use flutter-edge-ai-inference.
flutter_edge_ai and flutter_edge_ai_speech, and import both. The speech package does not re-export core.transcribe takes raw PCM — 16 kHz, mono, 16-bit little-endian, as a Uint8List — and returns the text. Not a WAV file, not 44.1 or 48 kHz: nothing resamples or converts it.synth.sampleRate. It differs per model.ArgumentError.getActiveStt(language:) or override one call with transcribe(pcm, language:). Nothing reloads.close() the synthesizer first. Asking a live synthesizer for another language throws StateError.minSdk 30. There is no web support — the web backends throw UnsupportedError.recognizer.transcribeStream(stream), on Parakeet only: check recognizer.streaming != null first (moonshine and Whisper fail with UnsupportedError). VoiceActivityDetector finds where speech starts and ends; it is native only.flutter pub add flutter_edge_ai flutter_edge_ai_speech
import 'package:flutter_edge_ai/flutter_edge_ai.dart';
import 'package:flutter_edge_ai_speech/flutter_edge_ai_speech.dart';
await FlutterEdgeAi.initialize(
sttBackends: [LiteRtSttBackend()],
ttsBackends: [LiteRtTtsBackend()],
);
Speech runs on the same native libraries as the .litertlm engine. Its build setup — Android minSdk 30, the Apple entries — is in the flutter-edge-ai-inference skill's platform setup, installed alongside this one.
An STT model is two files — the model and its tokenizer — usually from different repos. A catalog build (LiteRtSpeechModels, installed with installStt().fromCatalog) carries both, pinned to their Hugging Face commits; install() skips files already on disk. FlutterEdgeAi.installStt() installs your own files.
await FlutterEdgeAi.installStt().fromCatalog(LiteRtSpeechModels.whisperTiny.f32)
.install();
final SpeechRecognizer recognizer = await FlutterEdgeAi.getActiveStt(language: 'de');
try {
final String german = await recognizer.transcribe(germanPcm);
final String french = await recognizer.transcribe(frenchPcm, language: 'fr');
} finally {
await recognizer.close();
}
SttModelType | Languages | Window |
|---|---|---|
SttModelType.moonshine | English | 5 s |
SttModelType.whisper | 99, selectable, default 'en' | 30 s |
SttModelType.parakeet | English | 5 s; f32 is 2.35 GB, for desktop — on a Galaxy S23 (8 GB) its GPU load was killed. On a phone use the int8 parakeet_ctc_0.6b_5s_i8.tflite (596 MB) on the CPU (#747) |
On the GPU, run the f32 files: on Adreno 740 the int8 (_i8) ones did not compile there, and the load fails with an error naming the file.
Audio longer than the window is silently truncated, not rejected: it is zero-padded when shorter and cut when longer, so a 40-second clip on Whisper returns the first 30 seconds with no error. Split long recordings yourself.
Whisper tiny is weak outside English. Whisper base int8 is the next size up in the catalog: LiteRtSpeechModels.whisperBase.i8. Every speech build and where it has been run: https://flutteredge.ai/docs/registry.
Parakeet CTC transcribes a stream as it arrives (SpeechRecognizer.streaming is not null for it). Each update brings text that is final (TranscriptUpdate.confirmedDelta, append it) and a tail that may still change (TranscriptUpdate.unconfirmed, replace the previous one). The input is the same 16 kHz mono 16-bit PCM as transcribe, in chunks of any size: record at 16 kHz, nothing resamples.
final SpeechRecognizer recognizer = await FlutterEdgeAi.getActiveStt();
if (recognizer.streaming == null) {
throw StateError('this model does not stream: install Parakeet CTC');
}
final transcript = StringBuffer();
await for (final update in recognizer.transcribeStream(microphone)) {
transcript.write(update.confirmedDelta);
print('$transcript${update.unconfirmed}');
if (update.endpoint) print('utterance complete');
}
transcribe calls made meanwhile wait their turn.recognizer.flush() closes an utterance without ending the stream (call it at a voice activity detector's end of speech).SpeechStreamOverrunException after TranscribeStreamOptions.maxBufferedAudio (10 s); StreamingLatency.balanced halves the work of the default StreamingLatency.lowLatency.VoiceActivityDetector reports where speech starts and ends, with Silero VAD bundled in the package (nothing to download):
final vad = await VoiceActivityDetector.create();
try {
await for (final event in vad.detect(microphone)) {
switch (event) {
case VadSpeechStart(:final startSample):
print('speech from sample $startSample');
case VadSpeechEnd(:final startSample, :final endSample):
print('utterance: samples $startSample to $endSample');
}
}
} finally {
await vad.close();
}
Positions are 16 kHz sample indices from the stream's first sample (the utterance is pcm bytes 2 * startSample to 2 * endSample). A start arrives at least VadOptions.minSpeech (250 ms) after the voice began, at most about 0.9 s: keep that much audio to hand the whole utterance to speech-to-text. Silero hears any voice, a reply playing from the speaker included: barge-in needs echo cancellation.
The package has no resampler and no WAV reader. Record in the right format from the start — with the record package:
import 'package:record/record.dart';
const config = RecordConfig(
encoder: AudioEncoder.wav,
sampleRate: 16000,
numChannels: 1,
);
Recording needs microphone access. On Android record declares android.permission.RECORD_AUDIO in its own manifest and the manifest merger adds it to the app; iOS and macOS need entries of your own:
<!-- ios/Runner/Info.plist and macos/Runner/Info.plist -->
<key>NSMicrophoneUsageDescription</key>
<string>Speech is transcribed on this device.</string>
<!-- macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements -->
<key>com.apple.security.device.audio-input</key>
<true/>
The macOS sandbox withholds the microphone without the entitlement, and it has to be in both entitlements files. On Android, iOS and macOS the user must also allow it at run time; hasPermission() asks, so call it before recording:
final recorder = AudioRecorder();
if (!await recorder.hasPermission()) return;
That produces a WAV file. Its header is not always 44 bytes — take the samples from the data chunk:
import 'dart:typed_data';
/// The samples of a 16 kHz mono 16-bit WAV file, without its header.
Uint8List pcmFromWav(Uint8List wav) {
final view = ByteData.sublistView(wav);
var offset = 12; // after 'RIFF', the size and 'WAVE'
while (offset + 8 <= wav.length) {
final id = String.fromCharCodes(wav, offset, offset + 4);
final size = view.getUint32(offset + 4, Endian.little);
final start = offset + 8;
if (id == 'data') {
final end = start + size > wav.length ? wav.length : start + size;
return Uint8List.sublistView(wav, start, end);
}
offset = start + size + (size & 1); // chunks are padded to an even size
}
throw const FormatException('WAV file has no data chunk');
}
A file recorded at another rate or channel count — 44.1 kHz stereo, say — has to be converted first: average the channels to mono, then resample with a low-pass filter. Dropping samples instead aliases and costs accuracy.
Transcript comes back in English
'en' it translates. moonshine only ever produces English.language:.A language is rejected
'de', not 'de-DE', 'DE' or 'german'. Malformed codes throw ArgumentError from getActiveStt.'zz') throws ArgumentError from transcribe.await FlutterEdgeAi.installTts().fromCatalog(LiteRtSpeechModels.matchaTts.bundle)
.install();
final SpeechSynthesizer synth = await FlutterEdgeAi.getActiveTts();
try {
final audio = await synth.synthesize('Hello world.'); // 16-bit PCM
final rate = synth.sampleRate; // 22050 for Matcha
} finally {
await synth.close();
}
TtsModelType | Languages |
|---|---|
TtsModelType.matcha | English, fixed by the installed bundle — it ignores language: |
TtsModelType.qwen3 | chinese, english, german, italian, portuguese, spanish, japanese, korean, french, russian, or auto |
TtsModelType.inflect | English |
TtsModelType.supertonic and TtsModelType.kokoro are in the enum but throw UnimplementedError — do not use them.
To ship the voice with the app instead of downloading it, swap fromCatalog (or fromNetwork) for one of:
| Call | Expects | Notes |
|---|---|---|
fromAsset('assets/tts/matcha/') | Flutter asset directory laid out like the HF repo | Declare every subdirectory in pubspec.yaml (Qwen3 has tables/ and voices/); copied into app storage |
fromFile('/abs/dir') | Directory on disk, same layout | Used in place and stays the app's — uninstallTts() leaves these files |
fromBundled() | Native resources named <type>__<file>, e.g. matcha__config.json | Android assets/models/, iOS Runner target; Android and iOS only |
Inflect's four Matcha G2P files go next to its own two. A missing file fails install() with the full list before the current voice is replaced; a switch that fails partway (lost connection) leaves no voice active, so getActiveTts throws until install() is run again. install() throws UnsupportedError on web. To ship a changed voice in an app update, use a new asset directory (a bundled voice refreshes itself); with fromFile on iOS, call install() at launch, because the data directory moves on update.
Switching the Qwen3 language — full lowercase names, not ISO codes, and only with the Qwen3 bundle installed (Matcha still throws the same StateError but the language changes nothing):
final english = await FlutterEdgeAi.getActiveTts(language: 'english');
await english.close();
final german = await FlutterEdgeAi.getActiveTts(language: 'german');
Without the close(), the second call throws StateError: Active TTS synthesizer was created for language 'english'; call close() before requesting 'german'.
VoiceSession runs one push-to-talk turn: transcribe, generate, speak, with barge-in. It uses the recognizer's current language.
Wrap the loop in try/catch: a failed stage — transcribe, generate or synthesize — arrives as a stream error, not as an event. VoiceErrorEvent is reserved in this release and never emitted; the case is only there because the switch must be exhaustive. To barge in, call await voice.interrupt() — cancelling the subscription is not a portable stop.
final reply = StringBuffer();
final voice = VoiceSession.fromChat(
recognizer: await FlutterEdgeAi.getActiveStt(language: 'de'),
chat: chat,
synthesizer: await FlutterEdgeAi.getActiveTts(),
);
await for (final event in voice.runTurn(pcm16kMono)) {
switch (event) {
case VoiceTranscriptEvent(:final text):
print('heard: $text');
case VoiceReplyTextEvent(:final chunk):
reply.write(chunk);
case VoiceReplyAudioEvent(:final sampleRate):
print('audio at $sampleRate Hz');
case VoiceTurnInterruptedEvent():
print('interrupted — stop the player');
case VoiceTurnCompleteEvent():
print('done');
case VoiceErrorEvent(:final error):
print('failed: $error');
}
}
chat is an InferenceChat from the flutter-edge-ai-inference skill. A chat created with tools also needs onToolCall: — without it fromChat throws.
A model that hears audio (Gemma 4 or Gemma 3n E2B/E4B as .litertlm, native platforms only) can take the recording itself: runAudioTurn skips the transcription and sends the PCM to the chat. Set supportAudio: true on getActiveModel, which loads the audio encoder; openChat takes the flag from the model unless you pass it, and on a chat whose supportAudio is false runAudioTurn throws StateError. It takes the same 16 kHz mono 16-bit PCM as runTurn, and wraps it in a WAV header, because a .litertlm model decodes an audio file; a custom VoiceResponder.respondToAudio gets that WAV and can pass it to AgentSession.ask(audioBytes:) as is. There is no VoiceTranscriptEvent, the complete and interrupted events carry an empty transcript, and a recording under 2 bytes completes without asking the model. After a barge-in, a stopped partial exchange remains in chat history; current LiteRT-LM recovery either rewinds it or rebuilds from full message history, including earlier audio, so the next turn does not forget that media. Requires flutter_edge_ai_speech 0.5.7 or later.
final model = await FlutterEdgeAi.getActiveModel(
maxTokens: 4096,
supportAudio: true,
);
final chat = await model.openChat(supportAudio: true, maxOutputTokens: 128);
final voice = VoiceSession.fromChat(
recognizer: recognizer,
chat: chat,
synthesizer: synth,
);
try {
await for (final event in voice.runAudioTurn(pcm16kMono)) {
if (event is VoiceReplyTextEvent) print(event.chunk);
}
} finally {
await chat.close();
}
AFaffaan-m/ECC315k近 7 天新增 4,381 个 star
ANanthropics/skills203k近 7 天新增 3,265 个 star
HAharry0703/MoneyPrinterTurbo147k近 7 天新增 1,608 个 star
SHShubhamsaboo/awesome-llm-apps147k近 7 天新增 907 个 star
GAgarrytan/gstack143k近 7 天新增 598 个 star