Phonlet Wake on Android.

An AAR with the engine built for every common Android CPU.

The Android SDK is an AAR with the engine compiled natively for arm64-v8a, armeabi-v7a, and x86_64, and a small Java API you can call from Kotlin or Java.

Example

Wake.kt
// A phrase is its pronunciations and two calibrated thresholds.val keywords = """    [{"name": "hey kettle",      "pronunciations": [[16, 13, 20, 11, 31, 3, 21]],      "threshold_loose": -1.21875,      "threshold_strict": -0.8740234375,      "endpoint": true}]""".trimIndent() // One engine and one model for every phrase.val model = assets.open("en-1.pwake").readBytes()val wake = Wake.create(model, keywords, 0.5) // one per phrase // Push 16 kHz mono PCM from AudioRecord in chunks of any size.fun onAudio(pcm: ShortArray, samples: Int) {    val fired = wake.process(pcm, 0, samples) // -1: nothing    if (fired >= 0) Log.i("Wake", "Wake word: $fired")} // Release native memory when you are done.fun close() = wake.close()

How it works

  1. Ship the model as an app asset and pass the keyword file from the generator as JSON text (or just its phrase array), inline or from an asset.
  2. Create one Wake with one sensitivity per phrase. It is AutoCloseable, so use() or close() releases it.
  3. Record with AudioRecord at 16 kHz mono and pass each buffer to process(); it returns the phrase index or -1.

Good to know

  • Audio is mono, 16 kHz, signed 16-bit PCM. Push chunks of any size; the engine buffers them into 512-sample (32 ms) frames.
  • A phrase always comes with its thresholds: they are calibrated for that phrase and that model, and the engine needs them to decide when it was said. The generator makes them from text (phonletai.com/generator, or the wake-threshold command) and writes them into your keyword file.
  • Ask for the microphone permission after a deliberate user action, and stop recording when your screen or service stops.
  • One Wake is one continuous stream; keep it on the thread that reads the microphone.

Get the Android SDK

The Android SDK, the en-1 model and the threshold generator are in release v0.1.0, free for non-commercial use. For a product you sell, get a commercial licence.

Download phonlet-wake-android-0.1.0.aar into your app module's libs/ and add implementation(files("libs/phonlet-wake-android-0.1.0.aar")). In the example, en-1.pwake is phonlet-wake-en-1.pwake from the release, saved in the app's assets.