getActiveStt static method
Get the active STT model as a ready-to-use SpeechRecognizer
Returns a SpeechRecognizer configured with runtime parameters. The model and tokenizer paths come from the active SttModelSpec.
Runtime parameters:
preferredBackend: CPU or GPU preference (optional)
Throws:
- StateError if no active STT model is set
Example:
// Install STT model first
await FlutterGemma.installStt()
.modelFromNetwork('https://example.com/model.tflite')
.tokenizerFromNetwork('https://example.com/tokenizer.json')
.ofType(SttModelType.moonshine)
.install();
// Create with default backend
final recognizer = await FlutterGemma.getActiveStt();
Implementation
static Future<SpeechRecognizer> getActiveStt({
PreferredBackend? preferredBackend,
}) async {
final manager = FlutterGemmaPlugin.instance.modelManager;
final activeSpec = manager.activeSttModel;
if (activeSpec == null) {
throw StateError(
'No active STT model set. Use FlutterGemma.installStt() first.',
);
}
if (activeSpec is! SttModelSpec) {
throw StateError(
'Active model is not an SttModelSpec. '
'Expected SttModelSpec, got ${activeSpec.runtimeType}',
);
}
// Create SpeechRecognizer using active spec (paths resolved automatically)
return await FlutterGemmaPlugin.instance.createSttModel(
preferredBackend: preferredBackend,
);
}