main
md 99 lines 3.02 KB
Rendered Raw
1 # Apple MLX Support (`apple_mlx`)
2
3 Local package collecting experimental Dart wrappers around `lib_mlx`,
4 `speech_mlx`, and `mlx_audio`.
5
6 > **Development status:** Native LLM inference is disabled in LocalMind. The
7 > current `lib_mlx` 0.1.1 dependency ships a mock model core that returns stub
8 > responses; it does not execute downloaded MLX weights. Its bridge targets
9 > iOS only. The speech dependencies target macOS Apple Silicon and are not
10 > integrated into the LocalMind mobile app.
11
12 ## Capabilities
13
14 ### 1. LLM Text Generation (`AppleMlxLlmManager` & `lib_mlx`)
15 - **Prototype only**: Exercises the native lifecycle and local OpenAI-compatible
16 HTTP/SSE contract against the upstream mock core.
17 - **Not user-facing**: `AppleMlxCapabilities.nativeLlmInferenceAvailable` stays
18 `false` until a real, device-validated backend replaces the mock.
19
20 ### 2. Speech-To-Text (`AppleMlxSpeechManager` & `speech_mlx` / `mlx_audio`)
21 - **macOS only**: These dependencies do not provide iOS speech inference.
22 - **Parakeet-TDT & Whisper**: High-accuracy local speech recognition.
23 - **Isolate Offloading**: Dedicated worker isolates keep audio processing and resampling off the UI isolate.
24
25 ### 3. Text-To-Speech (`PocketTTS`)
26 - **Neural Voice Synthesis**: Real-time voice generation with incremental PCM streaming.
27 - **Voices**: Built-in multi-voice support (`alba`, `marius`, `javert`, `jean`).
28
29 ### 4. Conversational Turn Detection (`SmartTurn`)
30 - **Smart Turn v3.2**: Sub-millisecond endpoint classifier to determine whether a speaker finished speaking during a voice conversation.
31
32 ---
33
34 ## Quickstart
35
36 ### LLM Text Generation
37
38 The following example is for bridge development and contract testing only. It
39 does not perform real inference with `lib_mlx` 0.1.1.
40
41 ```dart
42 import 'package:apple_mlx/apple_mlx.dart';
43
44 Future<void> main() async {
45 final llm = AppleMlxLlmManager();
46
47 // 1. Load MLX model and launch local server
48 final serverInfo = await llm.loadAndStartServer(
49 modelPath: '/path/to/mlx-community/gemma-4-e2b-it-4bit',
50 modelId: AppleMlxModelIds.gemma4E2b,
51 thinkingEnabled: true,
52 );
53 print('MLX Server running on ${serverInfo.baseUrl}');
54
55 // 2. Stream generation
56 final stream = llm.generateStream(
57 messages: [
58 {'role': 'user', 'content': 'Explain quantum computing in simple terms.'},
59 ],
60 temperature: 0.7,
61 );
62
63 await for (final delta in stream) {
64 if (delta.reasoningContent != null) {
65 print('[Thinking] ${delta.reasoningContent}');
66 }
67 if (delta.content != null) {
68 print(delta.content);
69 }
70 }
71
72 // 3. Clean up
73 await llm.dispose();
74 }
75 ```
76
77 ### STT and TTS Audio
78
79 ```dart
80 import 'package:apple_mlx/apple_mlx.dart';
81
82 Future<void> main() async {
83 final speech = AppleMlxSpeechManager();
84 await speech.initialize();
85
86 // Transcribe audio
87 final text = await speech.transcribeWavFile('input.wav');
88 print('Transcript: $text');
89
90 // Synthesize voice
91 await speech.synthesizeToWav(
92 text: 'Hello from Apple MLX on LocalMind!',
93 outputPath: 'output.wav',
94 voice: 'alba',
95 );
96
97 await speech.dispose();
98 }
99 ```