Skip to content

Commit 010b31b

Browse files
refactor(android): reorganize codebase for easier navigation
- Split BibleDatabase (607 lines) into 7 domain DAOs: VerseDao, FavoritesDao, HighlightsDao, NotesDao, ReadingAnalyticsDao, InterlinearDao, LexiconDao. BibleDatabase now delegates to DAOs (zero API breakage). - Split SettingsScreens (531 lines) into one file per screen: SettingsComponents, GatewaySettingsPage, AudioSettingsPage, ReaderSettingsPage, UpdateSettingsPage under ui/screens/settings/. - Reorganized all 17 test files from flat root package to mirror main source structure (bible/, gateway/, models/, settings/, etc.) - Added gradle/libs.versions.toml version catalog (centralized all 22 dependency versions, removed inline version strings). - Removed enableJetifier=true (all deps are AndroidX-native). - Updated mobile/README.md to reflect current gateway-based architecture.
1 parent 4784a2e commit 010b31b

39 files changed

Lines changed: 1251 additions & 1200 deletions

mobile/README.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
# Metanoia Mobile TTS (Pixel 9 Pro Offline)
1+
# Metanoia Mobile
22

3-
This is a Kotlin port of the Metanoia TTS server, designed to run **Qwen3-TTS-0.6B** and **Whisper** locally on Android using **ONNX Runtime (ORT)** and **Tensor G4 NNAPI**.
3+
Kotlin/Compose Bible study app with gateway-proxied AI services (TTS, STT, interlinear, lexicon) and full offline Bible caching.
44

5-
## Repository Structure & Large Files
6-
To keep the repository lightweight, large binary files are **ignored by Git**. This includes:
7-
- **Models:** Any `.bin`, `.onnx`, `.data`, or `.npy` files in `mobile/app/src/main/assets/` or `mobile/models/`.
8-
- **Build Artifacts:** Android `build/` directories, `.apk` files, and `.aar` libraries.
5+
## Architecture
96

10-
### Model Placement
11-
After converting your models (see below), place them in:
12-
- `mobile/app/src/main/assets/`: For models used directly by the Android app.
13-
- `mobile/models/`: For raw or intermediate ONNX models.
14-
15-
Example required files (not in repo):
16-
- `mobile/app/src/main/assets/granite_350m_instruct.bin`
17-
- `mobile/models/vocoder.onnx`
18-
- `mobile/models/talker_decode.onnx.data`
7+
```
8+
mobile/app/src/main/java/com/bytecats/metanoia/
9+
├── bible/ Bible data layer (scraping, DB, analytics)
10+
│ └── dao/ Domain-specific database access objects
11+
├── gateway/ HTTP client for the Metanoia gateway server
12+
├── models/ Data classes and constants
13+
├── settings/ SharedPreferences wrapper
14+
├── stt/ Speech-to-text manager
15+
├── tts/ Text-to-speech manager and audio player
16+
├── update/ Nightly update checker and APK installer
17+
├── viewmodel/ MainViewModel (app-level state coordinator)
18+
└── ui/
19+
├── screens/ Full-screen Compose destinations
20+
│ └── settings/ Settings sub-screens (one per file)
21+
├── components/ Reusable Compose components
22+
│ └── bible/ Bible-specific UI (verse items, grids, sheets)
23+
└── theme/ Material3 theme definition
24+
```
1925

20-
## How to Port the Models
21-
The 0.6B PyTorch model cannot run directly in Kotlin. You must convert it to ONNX:
26+
## Build
2227

23-
### 1. Convert Qwen3-TTS to ONNX
2428
```bash
25-
python -m onnxruntime.tools.convert_onnx_models_to_ort
26-
--model_path qwen3_tts.onnx
27-
--output_dir app/src/main/assets/models/
28-
```
29-
*Note: Ensure you use INT8 quantization to keep the model under 700MB for mobile RAM.*
30-
31-
### 2. Convert Whisper to TFLite/ONNX
32-
For the transcribe feature, use the `whisper.cpp` optimized Android models or OpenAI's official TFLite conversion.
33-
34-
## Android Dependencies
35-
Add these to `build.gradle.kts`:
36-
```kotlin
37-
dependencies {
38-
implementation("com.microsoft.onnxruntime:onnxruntime-android:latest")
39-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
40-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
41-
}
29+
cd mobile
30+
./gradlew assembleDebug
4231
```
4332

44-
## Hardware Optimization
45-
On the Pixel 9 Pro, the **Tensor G4** chip supports `NNAPI`. When initializing the ONNX Session in `TTSManager.kt`, ensure you add the `NNAPI` execution provider for 10x faster generation.
33+
Requires Android SDK with API 35 platform tools. The `debug.keystore` is pinned in the repo for CI build identity consistency — see `app/build.gradle.kts` for the rationale.
34+
35+
## Dependencies
36+
37+
Dependency versions are centralized in `gradle/libs.versions.toml`. To update a library version, edit the `[versions]` section — library and plugin references pick it up automatically.
38+
39+
## Gateway
40+
41+
The app connects to a Metanoia gateway server (default `192.168.122.2:8000`) for:
42+
- Bible API (chapters, interlinear, lexicon, search)
43+
- TTS (Kokoro neural, voice clone)
44+
- STT (Whisper transcription)
45+
- Nightly update checks (GitHub releases)
46+
47+
Configure in Settings > Gateway Connection, or set `useGatewayBible = false` to fall back to direct web scraping for Bible text.

mobile/app/build.gradle.kts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
2-
id("com.android.application")
3-
id("org.jetbrains.kotlin.android")
4-
id("org.jetbrains.kotlin.plugin.compose")
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
55
}
66

77
android {
@@ -95,36 +95,36 @@ fun gitCommitCount(): Int = try {
9595
} catch (e: Exception) { 1 }
9696

9797
dependencies {
98-
implementation("androidx.core:core-ktx:1.15.0")
99-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
100-
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7") // REQUIRED
101-
implementation("androidx.activity:activity-compose:1.10.0")
102-
implementation(platform("androidx.compose:compose-bom:2025.02.00"))
103-
implementation("androidx.compose.ui:ui")
104-
implementation("androidx.compose.ui:ui-graphics")
105-
implementation("androidx.compose.ui:ui-tooling-preview")
106-
implementation("androidx.compose.material3:material3")
107-
implementation("androidx.compose.material:material-icons-extended")
108-
implementation("androidx.navigation:navigation-compose:2.8.7")
109-
implementation("androidx.core:core-splashscreen:1.0.1")
110-
98+
implementation(libs.androidx.core.ktx)
99+
implementation(libs.androidx.lifecycle.runtime.ktx)
100+
implementation(libs.androidx.lifecycle.viewmodel.compose)
101+
implementation(libs.androidx.activity.compose)
102+
implementation(platform(libs.androidx.compose.bom))
103+
implementation(libs.androidx.compose.ui)
104+
implementation(libs.androidx.compose.ui.graphics)
105+
implementation(libs.androidx.compose.ui.tooling.preview)
106+
implementation(libs.androidx.compose.material3)
107+
implementation(libs.androidx.compose.material.icons.extended)
108+
implementation(libs.androidx.navigation.compose)
109+
implementation(libs.androidx.core.splashscreen)
110+
111111
// --- CORE ENGINES ---
112-
implementation("com.microsoft.onnxruntime:onnxruntime-mobile:1.18.0")
112+
implementation(libs.onnxruntime.mobile)
113113

114114
// --- UTILS ---
115-
implementation("com.squareup.okhttp3:okhttp:4.12.0")
116-
implementation("org.jsoup:jsoup:1.17.2")
117-
118-
implementation("androidx.compose.ui:ui-text-google-fonts:1.7.8")
119-
120-
testImplementation("junit:junit:4.13.2")
121-
testImplementation("org.mockito:mockito-core:5.11.0")
122-
testImplementation("org.mockito.kotlin:mockito-kotlin:5.2.1")
123-
testImplementation("org.json:json:20240303")
124-
androidTestImplementation("androidx.test.ext:junit:1.2.1")
125-
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
126-
androidTestImplementation(platform("androidx.compose:compose-bom:2025.02.00"))
127-
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
128-
debugImplementation("androidx.compose.ui:ui-tooling")
129-
debugImplementation("androidx.compose.ui:ui-test-manifest")
115+
implementation(libs.okhttp)
116+
implementation(libs.jsoup)
117+
118+
implementation(libs.androidx.compose.ui.text.google.fonts)
119+
120+
testImplementation(libs.junit)
121+
testImplementation(libs.mockito.core)
122+
testImplementation(libs.mockito.kotlin)
123+
testImplementation(libs.org.json)
124+
androidTestImplementation(libs.androidx.test.ext.junit)
125+
androidTestImplementation(libs.androidx.test.espresso.core)
126+
androidTestImplementation(platform(libs.androidx.compose.bom))
127+
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
128+
debugImplementation(libs.androidx.compose.ui.tooling)
129+
debugImplementation(libs.androidx.compose.ui.test.manifest)
130130
}

mobile/app/src/main/java/com/bytecats/metanoia/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.navigation.compose.composable
1616
import androidx.navigation.compose.rememberNavController
1717
import com.bytecats.metanoia.bible.DeepLink
1818
import com.bytecats.metanoia.ui.screens.*
19+
import com.bytecats.metanoia.ui.screens.settings.*
1920
import com.bytecats.metanoia.ui.theme.MetanoiaTheme
2021
import com.bytecats.metanoia.viewmodel.MainViewModel
2122
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen

0 commit comments

Comments
 (0)