EarLLM One — Build & Maintain
Overview
Build, maintain, and extend the EarLLM One Android project — a Kotlin/Compose app that connects Bluetooth earbuds to an LLM via voice pipeline.
When to Use This Skill
- When the user mentions "earllm" or related topics
- When the user mentions "earbudllm" or related topics
- When the user mentions "earbud app" or related topics
- When the user mentions "voice pipeline kotlin" or related topics
- When the user mentions "bluetooth audio android" or related topics
- When the user mentions "sco microphone" or related topics
Do Not Use This Skill When
- The task is unrelated to earllm build
- A simpler, more specific tool can handle the request
- The user needs general-purpose assistance without domain expertise
How It Works
EarLLM One is a multi-module Android app (Kotlin + Jetpack Compose) that captures voice from Bluetooth earbuds, transcribes it, sends it to an LLM, and speaks the response back.
Project Location
C:\Users\renat\earbudllm
Module Dependency Graph
app ──→ voice ──→ audio ──→ core-logging
│ │
├──→ bluetooth ──→ core-logging
└──→ llm ──→ core-logging
Modules And Key Files
| Module |
Purpose |
Key Files |
| core-logging |
Structured logging, performance tracking |
EarLogger.kt, PerformanceTracker.kt |
| bluetooth |
BT discovery, pairing, A2DP/HFP profiles |
BluetoothController.kt, BluetoothState.kt, BluetoothPermissions.kt |
| audio |
Audio routing (SCO/BLE), capture, headset buttons |
AudioRouteController.kt, VoiceCaptureController.kt, HeadsetButtonController.kt |
| voice |
STT (SpeechRecognizer + Vosk stub), TTS, pipeline |
SpeechToTextController.kt, TextToSpeechController.kt, VoicePipeline.kt |
| llm |
LLM interface, stub, OpenAI-compatible client |
LlmClient.kt, StubLlmClient.kt, RealLlmClient.kt, SecureTokenStore.kt |
| app |
UI, ViewModel, Service, Settings, all screens |
MainViewModel.kt, EarLlmForegroundService.kt, 6 Compose screens |
Build Configuration
- SDK: minSdk 26, targetSdk 34, compileSdk 34
- Build tools: AGP 8.2.2, Kotlin 1.9.22, Gradle 8.5
- Compose BOM: 2024.02.00
- Key deps: OkHttp, AndroidX Security (EncryptedSharedPreferences), DataStore, Media
Target Hardware
| Device |
Model |
Key Details |
| Phone |
Samsung Galaxy S24 Ultra |
Android 14, One UI 6.1, Snapdragon 8 Gen 3 |
| Earbuds |
Xiaomi Redmi Buds 6 Pro |
BT 5.3, A2DP/HFP/AVRCP, ANC, LDAC |
Critical Technical Facts
These are verified facts from official documentation and device testing. Treat them as ground truth when making decisions:
Bluetooth SCO is limited to 8kHz mono input on most devices. Some support 16kHz mSBC. BLE Audio (Android 12+, TYPE_BLE_HEADSET = 26) supports up to 32kHz stereo. Always prefer BLE Audio when available.
startBluetoothSco() is deprecated since Android 12 (API 31). Use AudioManager.setCommunicationDevice(AudioDeviceInfo) and clearCommunicationDevice() instead. The project already implements both paths in AudioRouteController.kt.
Samsung One UI 7/8 has a known HFP corruption bug where A2DP playback corrupts the SCO link. The app handles this with silence detection and automatic fallback to the phone's built-in mic.
Redmi Buds 6 Pro tap controls must be set to "Default" (Play/Pause) in the Xiaomi Earbuds companion app. If set to ANC or custom functions, events are handled internally by the earbuds and never reach Android.
Android 14+ requires FOREGROUND_SERVICE_MICROPHONE permission and foregroundServiceType="microphone" in the service declaration. RECORD_AUDIO must be granted before startForeground().
VOICE_COMMUNICATION audio source enables AEC (Acoustic Echo Cancellation), which is critical to prevent TTS audio output from feeding back into the STT microphone input. Never change this source without understanding the echo implications.
Never play TTS (A2DP) while simultaneously recording via SCO. The correct sequence is: stop playback → switch to HFP → record → switch to A2DP → play response.
Data Flow
Headset button tap
→ MediaSession (HeadsetButtonController)
→ TapAction.RECORD_TOGGLE
→ VoicePipeline.toggleRecording()
→ VoiceCaptureController captures PCM (16kHz mono)
→ stopRecording() returns ByteArray
→ SpeechToTextController.transcribe(pcmData)
→ LlmClient.chat(messages)
→ TextToSpeechController.speak(response)
→ Audio output via A2DP to earbuds
Adding A New Feature
- Identify which module(s) are affected
- Read existing code in those modules first
- Follow the StateFlow pattern — expose state via
MutableStateFlow / StateFlow
- Update
MainViewModel.kt if the feature needs UI integration
- Add unit tests in the module's
src/test/ directory
- Update docs if the feature changes behavior
Modifying Audio Capture
VoiceCaptureController.kt handles PCM recording at 16kHz mono
- WAV headers use hex byte values (not char literals) to avoid shell quoting issues
- VU meter: RMS calculation → dB conversion → normalized 0-1 range
- Buffer size:
getMinBufferSize().coerceAtLeast(4096)
Changing Bluetooth Behavior
BluetoothController.kt manages discovery, pairing, profile proxies
- Earbuds detection uses name heuristics: "buds", "earbuds", "tws", "pods", "ear"
- Always handle both Bluetooth Classic and BLE Audio paths
Modifying The Llm Integration
LlmClient.kt defines the interface — keep it generic
StubLlmClient.kt for offline testing (500ms simulated delay)
RealLlmClient.kt uses OkHttp to call OpenAI-compatible APIs
- API keys stored in
SecureTokenStore.kt (EncryptedSharedPreferences)
Generating A Build Artifact
After code changes, regenerate the ZIP:
## From Project Root
powershell -Command "Remove-Item 'EarLLM_One_v1.0.zip' -Force -ErrorAction SilentlyContinue; Compress-Archive -Path (Get-ChildItem -Exclude '*.zip','_zip_verify','.git') -DestinationPath 'EarLLM_One_v1.0.zip' -Force"
Running Tests
./gradlew test --stacktrace # Unit tests
./gradlew connectedAndroidTest # Instrumented tests (device required)
Phase 2 Roadmap
- Real-time streaming voice conversation with LLM through earbuds
- Smart assistant: categorize speech into meetings, shopping lists, memos, emails
- Vosk offline STT integration (currently stubbed)
- Wake-word detection to avoid keeping SCO open continuously
- Streaming TTS (Android built-in TTS does NOT support streaming)
Stt Engine Reference
| Engine |
Size |
WER |
Streaming |
Best For |
| Vosk small-en |
40 MB |
~10% |
Yes |
Real-time mobile |
| Vosk lgraph |
128 MB |
~8% |
Yes |
Better accuracy |
| Whisper tiny |
40 MB |
~10-12% |
No (batch) |
Post-utterance polish |
| Android SpeechRecognizer |
0 MB |
varies |
Yes |
Online, no extra deps |
Best Practices
- Provide clear, specific context about your project and requirements
- Review all suggestions before applying them to production code
- Combine with other complementary skills for comprehensive analysis
Common Pitfalls
- Using this skill for tasks outside its domain expertise
- Applying recommendations without understanding your specific context
- Not providing enough project context for accurate analysis
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: earllm-build3description: Build, maintain, and extend the EarLLM One Android project — a Kotlin/Compose app that connects Bluetooth earbuds to an LLM via voice pipeline.4---5
6# EarLLM One — Build & Maintain
7
8## Overview
9
10Build, maintain, and extend the EarLLM One Android project — a Kotlin/Compose app that connects Bluetooth earbuds to an LLM via voice pipeline.
11
12## When to Use This Skill
13
14- When the user mentions "earllm" or related topics
15- When the user mentions "earbudllm" or related topics
16- When the user mentions "earbud app" or related topics
17- When the user mentions "voice pipeline kotlin" or related topics
18- When the user mentions "bluetooth audio android" or related topics
19- When the user mentions "sco microphone" or related topics
20
21## Do Not Use This Skill When
22
23- The task is unrelated to earllm build
24- A simpler, more specific tool can handle the request
25- The user needs general-purpose assistance without domain expertise
26
27## How It Works
28
29EarLLM One is a multi-module Android app (Kotlin + Jetpack Compose) that captures voice from Bluetooth earbuds, transcribes it, sends it to an LLM, and speaks the response back.
30
31## Project Location
32
33`C:\Users\renat\earbudllm`
34
35## Module Dependency Graph
36
37```
38app ──→ voice ──→ audio ──→ core-logging
39 │ │
40 ├──→ bluetooth ──→ core-logging
41 └──→ llm ──→ core-logging
42```
43
44## Modules And Key Files
45
46| Module | Purpose | Key Files |
47|--------|---------|-----------|
48| **core-logging** | Structured logging, performance tracking | `EarLogger.kt`, `PerformanceTracker.kt` |
49| **bluetooth** | BT discovery, pairing, A2DP/HFP profiles | `BluetoothController.kt`, `BluetoothState.kt`, `BluetoothPermissions.kt` |
50| **audio** | Audio routing (SCO/BLE), capture, headset buttons | `AudioRouteController.kt`, `VoiceCaptureController.kt`, `HeadsetButtonController.kt` |
51| **voice** | STT (SpeechRecognizer + Vosk stub), TTS, pipeline | `SpeechToTextController.kt`, `TextToSpeechController.kt`, `VoicePipeline.kt` |
52| **llm** | LLM interface, stub, OpenAI-compatible client | `LlmClient.kt`, `StubLlmClient.kt`, `RealLlmClient.kt`, `SecureTokenStore.kt` |
53| **app** | UI, ViewModel, Service, Settings, all screens | `MainViewModel.kt`, `EarLlmForegroundService.kt`, 6 Compose screens |
54
55## Build Configuration
56
57- **SDK**: minSdk 26, targetSdk 34, compileSdk 34
58- **Build tools**: AGP 8.2.2, Kotlin 1.9.22, Gradle 8.5
59- **Compose BOM**: 2024.02.00
60- **Key deps**: OkHttp, AndroidX Security (EncryptedSharedPreferences), DataStore, Media
61
62## Target Hardware
63
64| Device | Model | Key Details |
65|--------|-------|-------------|
66| Phone | Samsung Galaxy S24 Ultra | Android 14, One UI 6.1, Snapdragon 8 Gen 3 |
67| Earbuds | Xiaomi Redmi Buds 6 Pro | BT 5.3, A2DP/HFP/AVRCP, ANC, LDAC |
68
69## Critical Technical Facts
70
71These are verified facts from official documentation and device testing. Treat them as ground truth when making decisions:
72
731. **Bluetooth SCO is limited to 8kHz mono input** on most devices. Some support 16kHz mSBC. BLE Audio (Android 12+, `TYPE_BLE_HEADSET = 26`) supports up to 32kHz stereo. Always prefer BLE Audio when available.
74
752. **`startBluetoothSco()` is deprecated since Android 12 (API 31).** Use `AudioManager.setCommunicationDevice(AudioDeviceInfo)` and `clearCommunicationDevice()` instead. The project already implements both paths in `AudioRouteController.kt`.
76
773. **Samsung One UI 7/8 has a known HFP corruption bug** where A2DP playback corrupts the SCO link. The app handles this with silence detection and automatic fallback to the phone's built-in mic.
78
794. **Redmi Buds 6 Pro tap controls must be set to "Default" (Play/Pause)** in the Xiaomi Earbuds companion app. If set to ANC or custom functions, events are handled internally by the earbuds and never reach Android.
80
815. **Android 14+ requires `FOREGROUND_SERVICE_MICROPHONE` permission** and `foregroundServiceType="microphone"` in the service declaration. `RECORD_AUDIO` must be granted before `startForeground()`.
82
836. **`VOICE_COMMUNICATION` audio source enables AEC** (Acoustic Echo Cancellation), which is critical to prevent TTS audio output from feeding back into the STT microphone input. Never change this source without understanding the echo implications.
84
857. **Never play TTS (A2DP) while simultaneously recording via SCO.** The correct sequence is: stop playback → switch to HFP → record → switch to A2DP → play response.
86
87## Data Flow
88
89```
90Headset button tap
91 → MediaSession (HeadsetButtonController)
92 → TapAction.RECORD_TOGGLE
93 → VoicePipeline.toggleRecording()
94 → VoiceCaptureController captures PCM (16kHz mono)
95 → stopRecording() returns ByteArray
96 → SpeechToTextController.transcribe(pcmData)
97 → LlmClient.chat(messages)
98 → TextToSpeechController.speak(response)
99 → Audio output via A2DP to earbuds
100```
101
102## Adding A New Feature
103
1041. Identify which module(s) are affected
1052. Read existing code in those modules first
1063. Follow the StateFlow pattern — expose state via `MutableStateFlow` / `StateFlow`
1074. Update `MainViewModel.kt` if the feature needs UI integration
1085. Add unit tests in the module's `src/test/` directory
1096. Update docs if the feature changes behavior
110
111## Modifying Audio Capture
112
113- `VoiceCaptureController.kt` handles PCM recording at 16kHz mono
114- WAV headers use hex byte values (not char literals) to avoid shell quoting issues
115- VU meter: RMS calculation → dB conversion → normalized 0-1 range
116- Buffer size: `getMinBufferSize().coerceAtLeast(4096)`
117
118## Changing Bluetooth Behavior
119
120- `BluetoothController.kt` manages discovery, pairing, profile proxies
121- Earbuds detection uses name heuristics: "buds", "earbuds", "tws", "pods", "ear"
122- Always handle both Bluetooth Classic and BLE Audio paths
123
124## Modifying The Llm Integration
125
126- `LlmClient.kt` defines the interface — keep it generic
127- `StubLlmClient.kt` for offline testing (500ms simulated delay)
128- `RealLlmClient.kt` uses OkHttp to call OpenAI-compatible APIs
129- API keys stored in `SecureTokenStore.kt` (EncryptedSharedPreferences)
130
131## Generating A Build Artifact
132
133After code changes, regenerate the ZIP:
134```powershell
135
136## From Project Root
137
138powershell -Command "Remove-Item 'EarLLM_One_v1.0.zip' -Force -ErrorAction SilentlyContinue; Compress-Archive -Path (Get-ChildItem -Exclude '*.zip','_zip_verify','.git') -DestinationPath 'EarLLM_One_v1.0.zip' -Force"
139```
140
141## Running Tests
142
143```bash
144./gradlew test --stacktrace # Unit tests
145./gradlew connectedAndroidTest # Instrumented tests (device required)
146```
147
148## Phase 2 Roadmap
149
150- Real-time streaming voice conversation with LLM through earbuds
151- Smart assistant: categorize speech into meetings, shopping lists, memos, emails
152- Vosk offline STT integration (currently stubbed)
153- Wake-word detection to avoid keeping SCO open continuously
154- Streaming TTS (Android built-in TTS does NOT support streaming)
155
156## Stt Engine Reference
157
158| Engine | Size | WER | Streaming | Best For |
159|--------|------|-----|-----------|----------|
160| Vosk small-en | 40 MB | ~10% | Yes | Real-time mobile |
161| Vosk lgraph | 128 MB | ~8% | Yes | Better accuracy |
162| Whisper tiny | 40 MB | ~10-12% | No (batch) | Post-utterance polish |
163| Android SpeechRecognizer | 0 MB | varies | Yes | Online, no extra deps |
164
165## Best Practices
166
167- Provide clear, specific context about your project and requirements
168- Review all suggestions before applying them to production code
169- Combine with other complementary skills for comprehensive analysis
170
171## Common Pitfalls
172
173- Using this skill for tasks outside its domain expertise
174- Applying recommendations without understanding your specific context
175- Not providing enough project context for accurate analysis
176
177## Limitations
178- Use this skill only when the task clearly matches the scope described above.
179- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
180- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.