Phonlet Wake in C and C++.

One header and one library for native apps, embedded Linux, and your own SDK.

The C API is one header, phonlet_wake.h, and one library: the supported, stable public interface of the engine. It is tested on Linux x64; the Android and ESP32-S3 SDKs are built on it.

Example

wake.c
#include <stdio.h>#include "phonlet_wake.h" // A phrase is its pronunciations and two calibrated thresholds.static const char *keywords =    "[{\"name\": \"hey kettle\","    "  \"pronunciations\": [[16, 13, 20, 11, 31, 3, 21]],"    "  \"threshold_loose\": -1.21875,"    "  \"threshold_strict\": -0.8740234375,"    "  \"endpoint\": true}]"; static pw_wake *wake; // One engine and one model for every phrase.int start(void) {  const double sensitivity[] = {0.5}; // one per phrase  return phonlet_wake_init("en-1.pwake", keywords, sensitivity, 1,                           &wake);} // Push 16 kHz mono int16 PCM in chunks of any size.void on_audio(const int16_t *pcm, int32_t samples) {  int32_t fired = -1;  if (phonlet_wake_process(wake, pcm, samples, &fired) == PW_OK      && fired >= 0)    printf("Wake word: %d\n", fired);} // Release the session when you are done.void stop(void) { phonlet_wake_delete(wake); }

How it works

  1. phonlet_wake_init() loads the model from a path; phonlet_wake_init_bytes() takes it from memory, for example from flash.
  2. Pass the keyword file from the generator as JSON text (or just its phrase array); phonlet_wake_keyword_count() tells you how many phrases it holds. Give one sensitivity per phrase, from 0 (fewest false alarms) to 1 (most responsive).
  3. phonlet_wake_process() reports the index of the first phrase detected in that call, or -1.
  4. phonlet_wake_delete() releases the session; phonlet_wake_error() describes the last error on this thread.

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.
  • One session is one continuous audio stream. Use one session per stream and per thread.
  • Because each call reports its first detection, push short chunks (for example one I2S or audio-callback buffer) rather than long recordings.

Get the C / C++ SDK

The C / C++ 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.

Terminal
curl -LO https://github.com/phonlet-ai/wake/releases/download/v0.1.0/wake-native-0.1.0-linux-x64-gnu.tar.gztar xzf wake-native-0.1.0-linux-x64-gnu.tar.gz# CMake: find_package(Wake) and link Wake::engine,# configured with -DCMAKE_PREFIX_PATH=$PWD/wake-native-0.1.0

Linux x64: wake-native-0.1.0-linux-x64-gnu.tar.gz (header, libkws_engine.so, CMake package). Windows x64: wake-native-0.1.0-windows-x64.zip (kws_engine.dll and its import library). In the example, en-1.pwake is phonlet-wake-en-1.pwake from the release.