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
94 changes: 21 additions & 73 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ crate-type = ["cdylib", "staticlib"]
default = ["native-transcription"]
native-transcription = ["dep:ort", "dep:transcribe-rs"]
ios-onnx = ["native-transcription"]
ios-dual-backend = ["ios-onnx", "transcribe-rs/whisper"]
android-dual-backend = ["native-transcription", "transcribe-rs/whisper"]
whisper-mobile-spike = ["dep:sha2", "dep:transcribe-rs", "transcribe-rs/whisper"]

[dependencies]
log = "0.4"
once_cell = "1.19"
serde_json = "1"
transcribe-rs = { path = "transcribe-rs", optional = true }
transcribe-rs = { path = "transcribe-rs", optional = true, default-features = false, features = ["parakeet"] }
ort = { version = "=2.0.0-rc.10", optional = true }
sha2 = { version = "0.10", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13"
Expand Down
31 changes: 28 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ val hasReleaseSigning = listOf(
releaseKeyAlias,
releaseKeyPassword,
).all { !it.isNullOrBlank() }
val cargoExecutable = System.getenv("CARGO")
?: File(System.getProperty("user.home"), ".cargo/bin/cargo").takeIf(File::isFile)?.absolutePath
?: "cargo"

android {
namespace = "me.maxistar.voiceinbox"
Expand All @@ -24,8 +27,8 @@ android {
applicationId = "me.maxistar.voiceinbox"
minSdk = 24
targetSdk = 36
versionCode = 4
versionName = "0.2.2"
versionCode = 5
versionName = "0.2.3"
ndk {
abiFilters += "arm64-v8a"
}
Expand Down Expand Up @@ -122,17 +125,39 @@ val cargoNdkBuild by tasks.registering(Exec::class) {
?: System.getenv("ANDROID_NDK")
?: android.ndkDirectory.absolutePath
environment("ANDROID_NDK_HOME", ndkDir)
val ndkPrebuiltDir = File(ndkDir, "toolchains/llvm/prebuilt").listFiles()
?.firstOrNull(File::isDirectory) ?: throw GradleException("NDK LLVM prebuilt directory was not found")
val whisperCompatDir = layout.buildDirectory.dir("whisper-android-compat").get().asFile.apply { mkdirs() }
val whisperCompatArchive = File(whisperCompatDir, "libggml-blas.a")
if (!whisperCompatArchive.exists()) {
exec { commandLine(File(ndkPrebuiltDir, "bin/llvm-ar").absolutePath, "crs", whisperCompatArchive.absolutePath) }
}
val cmake = File(android.sdkDirectory, "cmake").listFiles()
?.sortedByDescending(File::getName)
?.map { File(it, "bin/cmake") }
?.firstOrNull(File::isFile)
?: throw GradleException("Android SDK CMake is required for the Whisper build")
environment("CMAKE", cmake.absolutePath)
environment("CMAKE_GENERATOR", "Ninja")
environment("CMAKE_MAKE_PROGRAM", File(cmake.parentFile, "ninja").absolutePath)
environment("CMAKE_ANDROID_ARCH_ABI", "arm64-v8a")
environment("RUSTFLAGS", "-Lnative=${whisperCompatDir.absolutePath}")
environment(
"CMAKE_TOOLCHAIN_FILE",
rootProject.file("scripts/whisper-android-cmake/android.toolchain.cmake").absolutePath,
)

val extractDir = layout.buildDirectory.dir("ort-extracted").get().asFile
environment("ORT_LIB_LOCATION", File(extractDir, "jni/arm64-v8a").absolutePath)
environment("ORT_INCLUDE_DIR", File(extractDir, "headers").absolutePath)

val jniLibsDir = project.file("src/main/jniLibs")
commandLine(
"cargo", "ndk",
cargoExecutable, "ndk",
"-t", "arm64-v8a",
"-o", jniLibsDir.absolutePath,
"build", "--release",
"--features", "android-dual-backend",
)

doLast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class EndToEndTranscriptionInstrumentedTest {

@Test
fun wavAndM4aBatchAppendSeparateTranscriptEntries() {
val model = SpeechModelRepository(targetContext.noBackupFilesDir.resolve("models")).inspect()
val model = SpeechModelRepository(
targetContext.noBackupFilesDir.resolve("models"),
SpeechModelCatalog.defaultModel.manifest,
).inspect()
assumeTrue(model is InstalledSpeechModelState.Ready)
targetContext.deleteDatabase(AndroidSqlDelightAudioCatalogFactory.DATABASE_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MainActivityInstrumentedTest {

openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().targetContext)
onView(withText(R.string.menu_settings)).check(matches(isDisplayed()))
onView(withText(R.string.menu_documentation)).check(matches(isDisplayed()))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ class SpeechModelLocalImporterInstrumentedTest {
)
val progress = mutableListOf<SpeechModelImportProgress>()

val installed = SpeechModelLocalImporter(context.contentResolver, repository)
val installed = SpeechModelLocalImporter(
repository = repository,
requiredDocuments = { _, _ ->
mapOf(
"recording.wav" to DocumentsContract.buildDocumentUriUsingTree(tree, "wav").toString(),
"recording.m4a" to DocumentsContract.buildDocumentUriUsingTree(tree, "m4a").toString(),
)
},
openInputStream = { context.contentResolver.openInputStream(Uri.parse(it)) },
)
.import(tree.toString()) { progress += it }
.getOrThrow()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.maxistar.voiceinbox

import android.content.Intent
import android.view.LayoutInflater
import android.widget.TextView
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TranscriptReviewInstrumentedTest {
@Test
fun shareIntentUsesExactPlainTextAndFilenameSubject() {
val review = AndroidTranscriptReview(5, "voice.ogg", " exact transcript\n")
val before = review.copy()

val intent = AndroidTranscriptShareIntent.create(review)

assertEquals(Intent.ACTION_SEND, intent.action)
assertEquals("text/plain", intent.type)
assertEquals(review.text, intent.getStringExtra(Intent.EXTRA_TEXT))
assertEquals(review.filename, intent.getStringExtra(Intent.EXTRA_SUBJECT))
assertEquals(before, review)
}

@Test
fun transcriptLayoutKeepsLongTextSelectableAndAccessible() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val view = LayoutInflater.from(context).inflate(R.layout.dialog_transcript, null)
val transcript = view.findViewById<TextView>(R.id.transcriptText)
val longText = "selectable transcript ".repeat(500)
transcript.text = longText

assertTrue(transcript.isTextSelectable)
assertEquals(longText, transcript.text.toString())
assertEquals(
context.getString(R.string.transcript_text_accessibility),
transcript.contentDescription,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ class TranscriptionWorkerInstrumentedTest {

private fun requireModel() {
assumeTrue(
SpeechModelRepository(targetContext.noBackupFilesDir.resolve("models")).inspect()
SpeechModelRepository(
targetContext.noBackupFilesDir.resolve("models"),
SpeechModelCatalog.defaultModel.manifest,
).inspect()
is InstalledSpeechModelState.Ready,
)
}
Expand Down
Loading
Loading