speech_kit 0.0.1
speech_kit: ^0.0.1 copied to clipboard
Native Dart bindings for Apple Speech (SpeechAnalyzer, SpeechTranscriber, AssetInventory) using Dart Build Hooks.
Speech for Dart #
Native Dart bindings for Apple Speech (SpeechAnalyzer pipeline) using Dart Build Hooks.
speech_kit exposes SpeechAnalyzer, SpeechTranscriber, DictationTranscriber, SpeechDetector, and AssetInventory from Dart with a small façade—not the legacy SFSpeechRecognizer / task-based API. Native code is compiled via hooks and bridged with FFI.
Features #
- Permissions — Speech recognition and microphone status / requests (native checks for usage-description keys where applicable)
- Asset inventory —
AssetInventory.status, download/install, andbestAvailableAudioFormatfor configured modules - Analysis sessions —
analyzeFile,analyzePcm,analyzePcmStreamwith optionalAnalysisContext,SpeechAnalyzerOptions, andprepareToAnalyze-style preparation with progress - Custom language model (training data) —
exportCustomLanguageModelDatawith phrase counts, custom pronunciations, and optionalPhraseCountsFromTemplatesConfig(template / compound tree) - Custom language model (compile) —
prepareCustomLanguageModelfrom exported training data;supportedCustomLanguagePhonemesper locale - Dictation integration —
SpeechLanguageModelPathsforSFSpeechLanguageModel.Configurationon dictation modules - Powered by Dart Build Hooks — No Flutter dependency (pure Dart on supported hosts)
Platform Support #
| Platform | Support |
|---|---|
| macOS | ✅ |
| Windows | ❌ |
| Linux | ❌ |
| iOS | ❌ |
| Android | ❌ |
macOS is the supported target for the native dylib in this release (platforms in pubspec.yaml is macOS-only). The module APIs used here require recent Apple OS releases (e.g. macOS 26+ for the current Swift bridge, consistent with iOS 26+ / visionOS 26+ for the same Speech symbols). Callers need dart:io (VM or an embedder that provides dart.library.io); non-IO configurations use stubs that throw UnsupportedError.
Installation #
Add the package:
dart pub add speech_kit
From a local path:
dependencies:
speech_kit:
path: ../speech-kit
Example #
import 'package:speech_kit/speech_kit.dart';
Future<void> main() async {
const kit = SpeechKit();
final speech = await kit.speechRecognitionAuthorizationStatus();
// Request permission if needed, build SpeechModuleConfiguration list,
// ensure assets, then analyzeFile / analyzePcm / analyzePcmStream.
}
Usage flow #
- Check permissions —
speechRecognitionAuthorizationStatus()/requestSpeechRecognitionPermission()and microphone APIs as needed. - Describe modules — Build a
List<SpeechModuleConfiguration>(transcriber, dictation, optional speech detector). - Assets —
assetInventoryStatus/ensureAssetsInstalled; usebestAvailableAudioFormatwhen preparing audio. - Analyze —
analyzeFile(or PCM / stream) with optionalAnalysisContext,SpeechAnalyzerOptions, and preparation callbacks. - Optional: custom LM —
exportCustomLanguageModelData→prepareCustomLanguageModel; attach compiled paths via dictation configuration when required. - Retention — Call
endSpeechModelRetentionwhen you no longer need models kept after analysis (if you used lingering / process-lifetime retention options).
For CLI samples (permission_status, asset_inventory, analyze_file), see example/README.md.
Architecture #
This package uses Dart Build Hooks to compile native code and bridge Apple’s Speech APIs to Dart.
Dart layers (inward dependencies): domain (value objects, errors) → application (SpeechKit façade, SpeechAnalysisSession) → infrastructure (macOS FFI + speech_kit_no_io stub). The public barrel exports domain types and the façade.
Dart (barrel + SpeechKit)
│
│ FFI
▼
Native bridge (Swift)
│
▼
Speech (Apple framework)
This keeps the Dart surface small while delegating OS work to the native library.
Example app #
See the example/ directory for command-line samples and macOS bundle notes.
Full instructions: example/README.md.
Roadmap #
Major capability areas implemented today are listed under Features: permissions, asset inventory, file/PCM/stream analysis with context and analyzer options, custom language model export (including template-based phrase counts), compile step, supported phonemes, and dictation LM paths.
Partially exposed or not exposed in the Dart API includes anything not covered in .cursor/skills/speech-kit-api-coverage/SKILL.md. iOS FFI is not wired in the current dart:io path; macOS is the supported desktop target for this release.
Additional documentation #
- Contributing — setup, tests, and PR guidelines
- Domain model — layers and value objects
- Apple Speech — Speech framework, SpeechAnalyzer, SFCustomLanguageModelData, advanced speech-to-text sample