Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/android-tts-audio-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: TTS Audio Test (Firebase Test Lab)

# Runs PocketTtsAudioOutputTest — the only test that puts real text through
# real sherpa-onnx + espeak-ng and asserts on the audio that comes out
# (issue #107).
#
# Why this needs its own workflow rather than joining ui-tests.yml:
# third-party/sherpa-onnx/sherpa-onnx-android.aar bundles arm64-v8a natives
# only (deliberate — see AAR_RESOLUTION.md), so the native library is simply
# absent on the x86_64 emulator ui-tests.yml boots, and the test self-skips
# there. Real signal needs real arm64 hardware, which on free infrastructure
# means a Firebase Test Lab physical device.
#
# Manual dispatch only: physical-device runs draw on the project's Test Lab
# quota and take ~10 min, so this is for release prep and for any change that
# touches the model, the espeak-ng data, the sherpa-onnx AAR, or the engine
# config — not for every push.

on:
workflow_dispatch:
inputs:
# Must be a PHYSICAL device: Test Lab's virtual devices are x86/x86_64
# and would just skip the test. Test Lab retires models over time (the
# once-standard "redfin" Pixel 5 is already gone), so re-check with
# gcloud firebase test android models list
# if a run reports an unknown model. Any arm64-v8a phone at API >= 31
# (the project's minSdk) works.
device_model:
description: "Test Lab physical device model id (must be arm64, API >= 31)"
required: false
default: "OP535DL1" # OnePlus Nord CE 2 Lite 5G — arm64-v8a, API 34
device_version:
description: "Android API level for that device"
required: false
default: "34"

concurrency:
group: tts-audio-test-${{ github.ref }}
cancel-in-progress: false

jobs:
audio-test:
name: Pocket TTS audio output (arm64 device)
runs-on: ubuntu-latest
timeout-minutes: 30
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Grant execute permission for gradlew
run: chmod +x gradlew

# core:tts is a library module, so this is the only APK produced: it is
# self-instrumenting (targetPackage == its own package) and already
# contains the arm64 natives, the ONNX voice model and espeak-ng-data.
- name: Assemble instrumentation test APK
run: ./gradlew :core:tts:assembleDebugAndroidTest

- name: Locate test APK
id: apk
run: |
APK=$(find core/tts/build/outputs/apk/androidTest -name '*.apk' | head -1)
if [ -z "$APK" ]; then
echo "::error::No androidTest APK was produced"
exit 1
fi
echo "Built $APK ($(du -h "$APK" | cut -f1))"
echo "path=$APK" >> "$GITHUB_OUTPUT"

# Reuses the service account already wired up for App Distribution. It
# additionally needs roles/cloudtestservice.testAdmin and
# roles/viewer on the project, plus the Cloud Testing and Cloud Tool
# Results APIs enabled — grant those once if this step 403s.
- name: Authenticate to Google Cloud
run: |
echo "${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON }}" | base64 --decode > "$RUNNER_TEMP/gcp-sa.json"
gcloud auth activate-service-account --key-file="$RUNNER_TEMP/gcp-sa.json"
echo "GOOGLE_CLOUD_PROJECT=$(jq -r .project_id "$RUNNER_TEMP/gcp-sa.json")" >> "$GITHUB_ENV"

# --app and --test are both required by gcloud, and for a self-
# instrumenting library test APK they are the same file. Test Lab
# installs it once and instruments it in place.
- name: Run on Firebase Test Lab
run: |
gcloud firebase test android run \
--type instrumentation \
--project "$GOOGLE_CLOUD_PROJECT" \
--app "${{ steps.apk.outputs.path }}" \
--test "${{ steps.apk.outputs.path }}" \
--device "model=${{ inputs.device_model }},version=${{ inputs.device_version }},locale=en,orientation=portrait" \
--test-targets "class xyz.libravault.core.tts.pocket.PocketTtsAudioOutputTest" \
--timeout 15m \
--results-dir "tts-audio-${{ github.run_id }}" \
--format json

- name: Clean up credentials
if: always()
run: rm -f "$RUNNER_TEMP/gcp-sa.json"

- name: Upload test APK for local reproduction
if: failure()
uses: actions/upload-artifact@v4
with:
name: tts-audio-test-apk-${{ github.run_number }}
path: ${{ steps.apk.outputs.path }}
retention-days: 7
3 changes: 2 additions & 1 deletion POCKET_TTS_PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ end to end:
turned out to be CC-BY-NC - non-commercial only, can't ship in this app) to
describe the single bundled VITS voice instead.
- `PocketTtsEngine.initialize()/speak()/setSpeechRate()` call the real
`OfflineTts` API (vendored as `core/tts/.../pocket/sherpa/Tts.kt`).
`OfflineTts` API (vendored as `core/tts/src/main/kotlin/com/k2fsa/sherpa/onnx/Tts.kt`
— that package is required for JNI symbol resolution, see AAR_RESOLUTION.md).

**iOS** (new):
- `PocketTTSEngine.swift` wraps the same sherpa-onnx C API (vendored as
Expand Down
12 changes: 12 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
-keep class androidx.pdf.** { *; }
-dontwarn androidx.pdf.**

# ── sherpa-onnx JNI (Pocket TTS) ──────────────────────────────────────────────
# libsherpa-onnx-jni.so uses *static* JNI registration: the runtime resolves
# each `external fun` to a symbol built from the fully-qualified class name
# (Java_com_k2fsa_sherpa_onnx_OfflineTts_newFromFile, ...), and the native side
# additionally reads the config data classes' fields by name via GetFieldID and
# constructs GeneratedAudio itself. R8 renaming any of that silently breaks
# every native call in release builds only - debug builds are not minified, so
# neither PocketTtsAudioOutputTest nor manual debug testing would catch it.
# Keep names and members for the whole vendored package.
-keep class com.k2fsa.sherpa.onnx.** { *; }
-keepclasseswithmembernames class com.k2fsa.sherpa.onnx.** { native <methods>; }

# ── Guava (MediaController) ───────────────────────────────────────────────────
-dontwarn com.google.common.**
-keep class com.google.common.util.concurrent.** { *; }
Expand Down
19 changes: 19 additions & 0 deletions core/tts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ if (!sherpaOnnxAar.exists()) {
android {
namespace = "xyz.libravault.core.tts"

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
buildConfig = true
}

sourceSets {
// PCM measurement helpers shared by the JVM unit tests (which check the
// math against synthetic waveforms, on every push) and the on-device
// audio test (which applies it to real sherpa-onnx output, only on
// arm64 hardware). Compiled into both test source sets rather than into
// main, since production code has no use for them.
getByName("test").kotlin.srcDir("src/testShared/kotlin")
getByName("androidTest").kotlin.srcDir("src/testShared/kotlin")
}

// Pocket TTS bundles exactly one voice: a Piper VITS model trained from
// scratch on the public-domain LJSpeech dataset. This was chosen over
// sherpa-onnx's own "Pocket TTS" model family (CC-BY-NC, non-commercial
Expand Down Expand Up @@ -53,4 +67,9 @@ dependencies {

testImplementation(libs.bundles.testing.jvm)
testRuntimeOnly(libs.junit5.engine)

// ── Instrumentation tests ──
// PocketTtsAudioOutputTest runs the real sherpa-onnx pipeline on device.
// The AAR is arm64-v8a only, so it self-skips elsewhere (see that file).
androidTestImplementation(libs.bundles.testing.instrumentation)
}
Loading
Loading