Skip to content

Commit bbd7c7f

Browse files
authored
Add Android demo for speaker recognition (#536)
See pre-built Android APKs at https://k2-fsa.github.io/sherpa/onnx/speaker-identification/apk.html
1 parent 626775e commit bbd7c7f

File tree

73 files changed

+3022
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3022
-6
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: apk-speaker-identification
2+
3+
on:
4+
push:
5+
branches:
6+
- apk
7+
tags:
8+
- '*'
9+
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: apk-speaker-identification-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
apk_tts:
21+
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa'
22+
runs-on: ${{ matrix.os }}
23+
name: apk for tts ${{ matrix.index }}/${{ matrix.total }}
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
os: [ubuntu-latest]
28+
total: ["10"]
29+
index: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
# https://github.com/actions/setup-java
37+
- uses: actions/setup-java@v4
38+
with:
39+
distribution: 'temurin' # See 'Supported distributions' for available options
40+
java-version: '21'
41+
42+
- name: ccache
43+
uses: hendrikmuhs/ccache-action@v1.2
44+
with:
45+
key: ${{ matrix.os }}-android
46+
47+
- name: Display NDK HOME
48+
shell: bash
49+
run: |
50+
echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}"
51+
ls -lh ${ANDROID_NDK_LATEST_HOME}
52+
53+
- name: Install Python dependencies
54+
shell: bash
55+
run: |
56+
python3 -m pip install --upgrade pip jinja2
57+
58+
- name: Generate build script
59+
shell: bash
60+
run: |
61+
cd scripts/apk
62+
63+
total=${{ matrix.total }}
64+
index=${{ matrix.index }}
65+
66+
./generate-speaker-identification-apk-script.py --total $total --index $index
67+
68+
chmod +x build-apk-speaker-identification.sh
69+
mv -v ./build-apk-speaker-identification.sh ../..
70+
71+
- name: build APK
72+
shell: bash
73+
run: |
74+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
75+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
76+
cmake --version
77+
78+
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME
79+
./build-apk-speaker-identification.sh
80+
81+
- name: Display APK
82+
shell: bash
83+
run: |
84+
ls -lh ./apks/
85+
du -h -d1 .
86+
87+
# - name: Release
88+
# uses: svenstaro/upload-release-action@v2
89+
# with:
90+
# file_glob: true
91+
# file: ./apks/*.apk
92+
# overwrite: true
93+
# repo_name: k2-fsa/sherpa-onnx
94+
# repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
95+
# tag: speaker-recongition-models
96+
97+
- name: Publish to huggingface
98+
if: true
99+
env:
100+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
101+
uses: nick-fields/retry@v2
102+
with:
103+
max_attempts: 20
104+
timeout_seconds: 200
105+
shell: bash
106+
command: |
107+
git config --global user.email "csukuangfj@gmail.com"
108+
git config --global user.name "Fangjun Kuang"
109+
110+
rm -rf huggingface
111+
export GIT_LFS_SKIP_SMUDGE=1
112+
113+
git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
114+
cd huggingface
115+
git fetch
116+
git pull
117+
git merge -m "merge remote" --ff origin main
118+
119+
mkdir -p speaker-identification
120+
cp -v ../apks/*.apk ./speaker-identification/
121+
git status
122+
git lfs track "*.apk"
123+
git add .
124+
git commit -m "add more apks"
125+
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk main

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
22
project(sherpa-onnx)
33

4-
set(SHERPA_ONNX_VERSION "1.9.7")
4+
set(SHERPA_ONNX_VERSION "1.9.8")
55

66
# Disable warning about
77
#
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.k2fsa.sherpa.onnx.speaker.identification"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
applicationId = "com.k2fsa.sherpa.onnx.speaker.identification"
12+
minSdk = 21
13+
targetSdk = 34
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary = true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
isMinifyEnabled = false
26+
proguardFiles(
27+
getDefaultProguardFile("proguard-android-optimize.txt"),
28+
"proguard-rules.pro"
29+
)
30+
}
31+
}
32+
compileOptions {
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
35+
}
36+
kotlinOptions {
37+
jvmTarget = "1.8"
38+
}
39+
buildFeatures {
40+
compose = true
41+
}
42+
composeOptions {
43+
kotlinCompilerExtensionVersion = "1.5.1"
44+
}
45+
packaging {
46+
resources {
47+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
48+
}
49+
}
50+
}
51+
52+
dependencies {
53+
54+
implementation("androidx.core:core-ktx:1.12.0")
55+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
56+
implementation("androidx.activity:activity-compose:1.8.2")
57+
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
58+
implementation("androidx.compose.ui:ui")
59+
implementation("androidx.compose.ui:ui-graphics")
60+
implementation("androidx.compose.ui:ui-tooling-preview")
61+
implementation("androidx.compose.material3:material3")
62+
implementation("androidx.navigation:navigation-compose:2.7.6")
63+
testImplementation("junit:junit:4.13.2")
64+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
65+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
66+
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
67+
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
68+
debugImplementation("androidx.compose.ui:ui-tooling")
69+
debugImplementation("androidx.compose.ui:ui-test-manifest")
70+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.k2fsa.sherpa.onnx.speaker.identification
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.k2fsa.sherpa.onnx.speaker.identification", appContext.packageName)
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:dataExtractionRules="@xml/data_extraction_rules"
10+
android:fullBackupContent="@xml/backup_rules"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.SherpaOnnxSpeakerIdentification"
16+
tools:targetApi="31">
17+
<activity
18+
android:name=".MainActivity"
19+
android:exported="true"
20+
android:label="@string/app_name"
21+
android:theme="@style/Theme.SherpaOnnxSpeakerIdentification">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
</application>
29+
30+
</manifest>

android/SherpaOnnxSpeakerIdentification/app/src/main/assets/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.k2fsa.sherpa.onnx.speaker.identification
2+
3+
import androidx.compose.ui.graphics.vector.ImageVector
4+
5+
data class BarItem (
6+
val title: String,
7+
8+
// see https://www.composables.com/icons
9+
// and
10+
// https://developer.android.com/reference/kotlin/androidx/compose/material/icons/filled/package-summary
11+
val image: ImageVector,
12+
val route: String,
13+
)

0 commit comments

Comments
 (0)