Upload 13 files
Browse files- .gitattributes +4 -0
- README.md +509 -0
- assets/architecture.png +0 -0
- assets/banner.png +3 -0
- assets/board-esp32.jpg +3 -0
- assets/board-stm32n657.jpg +3 -0
- assets/compute.png +0 -0
- assets/features.png +0 -0
- assets/memory.png +3 -0
- assets/on-device.png +0 -0
- assets/supervision.png +0 -0
- assets/temporal-block.png +0 -0
- assets/trigger.png +0 -0
- model_version0-2.tflite +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/banner.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/board-esp32.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/board-stm32n657.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/memory.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,3 +1,512 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- pa
|
| 5 |
+
- hi
|
| 6 |
+
library_name: tflite
|
| 7 |
+
pipeline_tag: audio-classification
|
| 8 |
+
tags:
|
| 9 |
+
- keyword-spotting
|
| 10 |
+
- wake-word
|
| 11 |
+
- streaming
|
| 12 |
+
- depthwise-separable-cnn
|
| 13 |
+
- tinyml
|
| 14 |
+
- microcontroller
|
| 15 |
+
- edge-ai
|
| 16 |
+
- int8
|
| 17 |
+
- stm32
|
| 18 |
+
- esp32
|
| 19 |
+
- punjabi
|
| 20 |
+
- hindi
|
| 21 |
+
datasets:
|
| 22 |
+
- SherTheCoder/TeamFolklore_UthoKikkar
|
| 23 |
---
|
| 24 |
+
|
| 25 |
+
<p align="center">
|
| 26 |
+
<img src="assets/banner.png" alt="The kikkar flower, from bud to full bloom" width="100%">
|
| 27 |
+
</p>
|
| 28 |
+
|
| 29 |
+
<h1 align="center">Kikkar KWS</h1>
|
| 30 |
+
|
| 31 |
+
<p align="center">
|
| 32 |
+
<b>A 44 KB int8 streaming model that listens for "Utho Kikkar" on a microcontroller, and for nothing else.</b><br>
|
| 33 |
+
We made it for projects and prototypes with less than 256 KB of free RAM
|
| 34 |
+
</p>
|
| 35 |
+
|
| 36 |
+
<p align="center">
|
| 37 |
+
<img src="https://img.shields.io/badge/task-keyword%20spotting-2a78d6" alt="Task: keyword spotting">
|
| 38 |
+
<img src="https://img.shields.io/badge/format-TFLite%20int8-4a3aa7" alt="Format: TFLite int8">
|
| 39 |
+
<img src="https://img.shields.io/badge/size-44%20KB-1baf7a" alt="Size: 44 KB">
|
| 40 |
+
<img src="https://img.shields.io/badge/runs%20on-STM32N657%20%7C%20ESP32-e8a33d" alt="Runs on STM32N657 and ESP32">
|
| 41 |
+
</p>
|
| 42 |
+
|
| 43 |
+
<table align="center">
|
| 44 |
+
<tr>
|
| 45 |
+
<td align="center" width="25%"><h2>44 KB</h2>in flash</td>
|
| 46 |
+
<td align="center" width="25%"><h2>32,849</h2>parameters</td>
|
| 47 |
+
<td align="center" width="25%"><h2>45,872</h2>multiply-accumulates per step</td>
|
| 48 |
+
<td align="center" width="25%"><h2>5</h2>layers</td>
|
| 49 |
+
</tr>
|
| 50 |
+
<tr>
|
| 51 |
+
<td align="center"><h2>30 ms</h2>per step</td>
|
| 52 |
+
<td align="center"><h2>≈ 1.5 s</h2>of context</td>
|
| 53 |
+
<td align="center"><h2>≈ 38 KB</h2>working memory</td>
|
| 54 |
+
<td align="center"><h2>60 ms</h2>phrase end to wake-up</td>
|
| 55 |
+
</tr>
|
| 56 |
+
</table>
|
| 57 |
+
|
| 58 |
+
## Overview & Wake-Word Detection
|
| 59 |
+
|
| 60 |
+
Our model listens in steps of 30 ms. At every step it takes the three newest
|
| 61 |
+
frames of log-mel energy, updates what it remembers of the last one and a half
|
| 62 |
+
seconds, and gives back one number: the chance that someone has just finished
|
| 63 |
+
saying *Utho Kikkar* (ਉੱਠੋ ਕਿੱਕਰ · उठो किक्कर), which means "wake up, Kikkar". We run it
|
| 64 |
+
entirely on the board, and no audio leaves the device until it fires.
|
| 65 |
+
|
| 66 |
+
We trained it to fire only at the end of the whole phrase. We taught it that
|
| 67 |
+
*Utho* on its own, *Kikkar* on its own, the two the wrong way round, and
|
| 68 |
+
everyday words that sound close, like *chakkar*, *shakkar* or *kicker*, are all
|
| 69 |
+
things that are not the wake word.
|
| 70 |
+
|
| 71 |
+
It is the listener inside Kikkar, our Smart India Hackathon 2026 project. When
|
| 72 |
+
it fires, a flower blooms on the board's screen and we stream whatever you say
|
| 73 |
+
next to a speech recogniser in the cloud.
|
| 74 |
+
|
| 75 |
+
| At a glance | |
|
| 76 |
+
|---|---|
|
| 77 |
+
| **Input** | 3 new log-mel frames × 40 bands per 30 ms step, int8 |
|
| 78 |
+
| **Output** | one probability per step: has "Utho Kikkar" just ended? |
|
| 79 |
+
| **Architecture** | Streaming depthwise-separable CNN, 5 layers |
|
| 80 |
+
| **Size** | 32,849 parameters, ≈ 44 KB of flash |
|
| 81 |
+
| **Compute** | 45,872 multiply-accumulates per step, 1.53 million a second |
|
| 82 |
+
| **Context** | ≈ 1.5 s of audio |
|
| 83 |
+
| **Latency** | 60 ms from the end of the phrase to the wake-up |
|
| 84 |
+
| **Format** | TensorFlow Lite, int8, streaming state kept inside the model |
|
| 85 |
+
| **Runs on** | STM32N657 (Cortex-M55) and ESP32 |
|
| 86 |
+
| **Trained on** | About 2,000 real recordings plus synthetic speech, including [SherTheCoder/TeamFolklore_UthoKikkar](https://huggingface.co/datasets/SherTheCoder/TeamFolklore_UthoKikkar) |
|
| 87 |
+
|
| 88 |
+
## Quickstart & Verification Pipeline
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
# pip install numpy soundfile tensorflow huggingface_hub
|
| 92 |
+
import numpy as np
|
| 93 |
+
import soundfile as sf
|
| 94 |
+
import tensorflow as tf
|
| 95 |
+
from huggingface_hub import hf_hub_download
|
| 96 |
+
|
| 97 |
+
path = hf_hub_download("SherTheCoder/TeamFolklore_Model", "kikkar_kws_int8.tflite")
|
| 98 |
+
interp = tf.lite.Interpreter(model_path=path)
|
| 99 |
+
interp.allocate_tensors()
|
| 100 |
+
inp, out = interp.get_input_details()[0], interp.get_output_details()[0]
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
We wrote the front end below to follow our model's specification. Features that are even
|
| 104 |
+
slightly different will quietly cost accuracy, so if your own pipeline differs
|
| 105 |
+
in any detail, trust that instead.
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
SR, WIN, HOP, NFFT, MELS, STEP = 16000, 480, 160, 512, 40, 3
|
| 109 |
+
|
| 110 |
+
def _mel(hz):
|
| 111 |
+
return 2595.0 * np.log10(1.0 + hz / 700.0)
|
| 112 |
+
|
| 113 |
+
def _hz(mel):
|
| 114 |
+
return 700.0 * (10.0 ** (mel / 2595.0) - 1.0)
|
| 115 |
+
|
| 116 |
+
_edges = _hz(np.linspace(_mel(20.0), _mel(7600.0), MELS + 2))
|
| 117 |
+
_bins = np.arange(NFFT // 2 + 1) * SR / NFFT
|
| 118 |
+
_fbank = np.zeros((MELS, NFFT // 2 + 1))
|
| 119 |
+
for b in range(MELS):
|
| 120 |
+
lo, mid, hi = _edges[b:b + 3]
|
| 121 |
+
rise = (_bins > lo) & (_bins < mid)
|
| 122 |
+
fall = (_bins >= mid) & (_bins < hi)
|
| 123 |
+
_fbank[b, rise] = (_bins[rise] - lo) / (mid - lo)
|
| 124 |
+
_fbank[b, fall] = (hi - _bins[fall]) / (hi - mid)
|
| 125 |
+
_hann = np.hanning(WIN)
|
| 126 |
+
|
| 127 |
+
def features(audio, cms_seconds=3.0):
|
| 128 |
+
"""16 kHz mono int16 in, 40 normalised log-mel values per 10 ms frame out."""
|
| 129 |
+
x = np.asarray(audio, dtype=np.float64) / 32768.0
|
| 130 |
+
frames = np.array([x[s:s + WIN] * _hann for s in range(0, len(x) - WIN + 1, HOP)])
|
| 131 |
+
power = np.abs(np.fft.rfft(frames, NFFT)) ** 2
|
| 132 |
+
logmel = np.log(np.maximum(power @ _fbank.T, 1e-8)) # floor at -80 dB
|
| 133 |
+
a = 1.0 - np.exp(-(HOP / SR) / cms_seconds)
|
| 134 |
+
mean = logmel[:50].mean(axis=0) # start from the first 0.5 s
|
| 135 |
+
out = np.empty_like(logmel)
|
| 136 |
+
for i, frame in enumerate(logmel):
|
| 137 |
+
mean += a * (frame - mean)
|
| 138 |
+
out[i] = frame - mean
|
| 139 |
+
return out
|
| 140 |
+
|
| 141 |
+
def wake_scores(audio):
|
| 142 |
+
"""One probability per 30 ms step, fed to the model the way the board feeds it."""
|
| 143 |
+
feats = features(audio)
|
| 144 |
+
interp.reset_all_variables() # fresh streaming state
|
| 145 |
+
scale, zero = inp["quantization"]
|
| 146 |
+
scores = []
|
| 147 |
+
for s in range(0, len(feats) - STEP + 1, STEP):
|
| 148 |
+
x = feats[s:s + STEP]
|
| 149 |
+
if inp["dtype"] == np.int8:
|
| 150 |
+
x = np.clip(np.round(x / scale) + zero, -128, 127)
|
| 151 |
+
interp.set_tensor(inp["index"], x.astype(inp["dtype"]).reshape(inp["shape"]))
|
| 152 |
+
interp.invoke()
|
| 153 |
+
scores.append(float(interp.get_tensor(out["index"]).reshape(-1)[0]))
|
| 154 |
+
return np.array(scores)
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Our model ends in a float sigmoid, so each score is already a probability. Then
|
| 158 |
+
point it at a clip:
|
| 159 |
+
|
| 160 |
+
```python
|
| 161 |
+
audio, sr = sf.read("clip.wav", dtype="int16")
|
| 162 |
+
assert sr == SR and audio.ndim == 1, "the model expects 16 kHz mono audio"
|
| 163 |
+
scores = wake_scores(audio)
|
| 164 |
+
smoothed = np.convolve(scores, np.ones(3) / 3)[:len(scores)] # the last 3 steps, 90 ms
|
| 165 |
+
print("highest smoothed score:", round(float(smoothed.max()), 3))
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
To see where the board would wake up (on the board we use a threshold of 0.7,
|
| 169 |
+
picked on the int8 model):
|
| 170 |
+
|
| 171 |
+
```python
|
| 172 |
+
def detect(audio, threshold, refractory_s=1.0):
|
| 173 |
+
"""Times, in seconds, at which the board would wake up."""
|
| 174 |
+
scores = wake_scores(audio)
|
| 175 |
+
smoothed = np.convolve(scores, np.ones(3) / 3)[:len(scores)]
|
| 176 |
+
wakes, last = [], -np.inf
|
| 177 |
+
for i, p in enumerate(smoothed):
|
| 178 |
+
t = ((i * STEP + STEP - 1) * HOP + WIN) / SR
|
| 179 |
+
if p >= threshold and t - last >= refractory_s:
|
| 180 |
+
wakes.append(round(t, 2))
|
| 181 |
+
last = t
|
| 182 |
+
return wakes
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
## Audio Frontend & Feature Extraction
|
| 186 |
+
|
| 187 |
+
<p align="center">
|
| 188 |
+
<img src="assets/features.png" alt="16 kHz audio, 30 ms Hann windows every 10 ms, 512-point power spectrum, 40 mel bands from 20 Hz to 7.6 kHz, log and running-mean normalisation, then 3 frames per 30 ms model step" width="100%">
|
| 189 |
+
</p>
|
| 190 |
+
|
| 191 |
+
| Stage | Setting | Output |
|
| 192 |
+
|---|---|---|
|
| 193 |
+
| Capture | 16 kHz, mono, 16-bit | 160 samples every 10 ms |
|
| 194 |
+
| Window | 30 ms Hann (480 samples), every 10 ms | 480 samples |
|
| 195 |
+
| FFT | 512-point, power spectrum | 257 bins |
|
| 196 |
+
| Mel | 40 triangular bands, 20 Hz to 7.6 kHz | 40 values |
|
| 197 |
+
| Compression | natural log, floored at −80 dB | 40 values |
|
| 198 |
+
| Normalisation | per-band running mean subtracted, τ ≈ 3 s | 40 × int8 |
|
| 199 |
+
| Model step | the 3 newest frames, every 30 ms | 3 × 40 |
|
| 200 |
+
|
| 201 |
+
We rely on the running mean to soak up the differences between microphones,
|
| 202 |
+
gain settings and rooms, so we do not need to recalibrate the board for every
|
| 203 |
+
house. We start it from the first half second of audio after boot.
|
| 204 |
+
|
| 205 |
+
## Model Architecture & Layer Specifications
|
| 206 |
+
|
| 207 |
+
We built a streaming depthwise-separable CNN in five layers. The first two work across
|
| 208 |
+
frequency while that axis still exists, learning spectral shapes cheaply. The
|
| 209 |
+
third folds frequency into a single 48-channel vector. Everything after that is
|
| 210 |
+
causal depthwise convolution over time plus 1×1 pointwise mixing, which we chose
|
| 211 |
+
because it streams as a small ring-buffer update at every step and is the int8
|
| 212 |
+
path that microcontroller kernels run fastest.
|
| 213 |
+
|
| 214 |
+
<p align="center">
|
| 215 |
+
<img src="assets/architecture.png" alt="Input of 3 new log-mel frames by 40 bands; S1 frequency stem to 3 by 20 by 16; S2 depthwise-separable block to 1 by 10 by 32; S3 collapse from 320 values to 48 channels; six causal temporal blocks at 48 channels; head from 48 to 1 with a sigmoid" width="100%">
|
| 216 |
+
</p>
|
| 217 |
+
|
| 218 |
+
### Layer Breakdown & Compute (MACs)
|
| 219 |
+
|
| 220 |
+
Shapes are per 30 ms step. We make every convolution over time causal, padded on
|
| 221 |
+
the left only, and every convolution over frequency keeps its size.
|
| 222 |
+
|
| 223 |
+
| # | Layer | Operation | Output (T, F, C) | Weights | MACs per step |
|
| 224 |
+
|---|---|---|---|---:|---:|
|
| 225 |
+
| S1 | Frequency stem | Conv2D 3×3, stride (1, 2), 1 → 16, BN, ReLU | 3, 20, 16 | 144 | 8,640 |
|
| 226 |
+
| S2a | Frequency depthwise | Depthwise Conv2D 3×3, stride (3, 2), 16 channels, BN, ReLU | 1, 10, 16 | 144 | 1,440 |
|
| 227 |
+
| S2b | Channel mix | Pointwise 16 → 32, BN, ReLU | 1, 10, 32 | 512 | 5,120 |
|
| 228 |
+
| S3 | Collapse | Flatten 10 × 32 = 320, 1×1 conv to 48, BN, ReLU | 1, 48 | 15,360 | 15,360 |
|
| 229 |
+
| B1 | Temporal block, d = 1 | Depthwise Conv1D k5, pointwise 48 → 48, residual | 1, 48 | 2,544 | 2,544 |
|
| 230 |
+
| B2 | Temporal block, d = 1 | same | 1, 48 | 2,544 | 2,544 |
|
| 231 |
+
| B3 | Temporal block, d = 2 | same | 1, 48 | 2,544 | 2,544 |
|
| 232 |
+
| B4 | Temporal block, d = 2 | same | 1, 48 | 2,544 | 2,544 |
|
| 233 |
+
| B5 | Temporal block, d = 3 | same | 1, 48 | 2,544 | 2,544 |
|
| 234 |
+
| B6 | Temporal block, d = 3 | same | 1, 48 | 2,544 | 2,544 |
|
| 235 |
+
| H | Head | Pointwise 48 → 1, sigmoid in float | 1, 1 | 48 | 48 |
|
| 236 |
+
|
| 237 |
+
<p align="center">
|
| 238 |
+
<img src="assets/temporal-block.png" alt="Inside each temporal block: a causal depthwise 1D convolution with kernel 5 and dilation d, batch norm and ReLU, a pointwise 48 to 48 convolution and batch norm, added back to the input, then ReLU" width="100%">
|
| 239 |
+
</p>
|
| 240 |
+
|
| 241 |
+
We picked dilations of 1, 1, 2, 2, 3, 3, which give the trunk 49 steps of
|
| 242 |
+
context, 1.47 s, and the stem and the window overhang add about 40 ms more:
|
| 243 |
+
≈ 1.51 s in all. We sized that to cover *Utho Kikkar*, which takes about 1.0 to
|
| 244 |
+
1.2 s to say, with room for slow speakers, and no more. Extra context would cost RAM and let the model latch on
|
| 245 |
+
to background sound.
|
| 246 |
+
|
| 247 |
+
<p align="center">
|
| 248 |
+
<img src="assets/compute.png" alt="Multiply-accumulates per step: S3 collapse 15,360 (33.5 percent), temporal blocks 15,264 (33.3 percent), S1 stem 8,640 (18.8 percent), S2 block 6,560 (14.3 percent), head 48 (0.1 percent)" width="100%">
|
| 249 |
+
</p>
|
| 250 |
+
|
| 251 |
+
| Parameters | Count |
|
| 252 |
+
|---|---:|
|
| 253 |
+
| Convolution weights, S1 to S3 | 16,160 |
|
| 254 |
+
| Convolution weights, B1 to B6 | 15,264 |
|
| 255 |
+
| Head weights | 48 |
|
| 256 |
+
| **Convolution subtotal** | **31,472** |
|
| 257 |
+
| Batch-norm scale and bias, folded (688 channels × 2) | 1,376 |
|
| 258 |
+
| Head bias | 1 |
|
| 259 |
+
| **Total** | **32,849** |
|
| 260 |
+
|
| 261 |
+
At 33.3 steps a second our model does 1.53 million multiply-accumulates a
|
| 262 |
+
second.
|
| 263 |
+
|
| 264 |
+
## RAM Allocation & Tensor Arena Budget
|
| 265 |
+
|
| 266 |
+
<p align="center">
|
| 267 |
+
<img src="assets/memory.png" alt="Design budget for the listening path: pre-roll ring 32 KB, TFLM tensor arena about 20 KB, task stacks 8 KB, FFT scratch 4 KB, interpreter about 3 KB, I2S DMA 1.3 KB, frame buffer 1.0 KB, mel and CMS state 0.4 KB, smoothing 0.1 KB" width="100%">
|
| 268 |
+
</p>
|
| 269 |
+
|
| 270 |
+
| Component | RAM |
|
| 271 |
+
|---|---:|
|
| 272 |
+
| I2S DMA buffers, 4 × 10 ms × int16 | 1.3 KB |
|
| 273 |
+
| Frame assembly buffer, 480 samples | 1.0 KB |
|
| 274 |
+
| FFT scratch, 512 complex float32 | 4.0 KB |
|
| 275 |
+
| Mel output and CMS running state | 0.4 KB |
|
| 276 |
+
| TFLM tensor arena: activations, kernel scratch and 2.3 KB of streaming state | ≈ 20 KB |
|
| 277 |
+
| Interpreter, op resolver and allocator | ≈ 3 KB |
|
| 278 |
+
| Smoothing and refractory state | 0.1 KB |
|
| 279 |
+
| Task stacks, audio and inference | 8 KB |
|
| 280 |
+
| **Keyword spotting in total** | **≈ 38 KB** |
|
| 281 |
+
| Pre-roll ring, 1 s at 16 kHz int16, for the hand-off to the ASR server | 32 KB |
|
| 282 |
+
| **Listening path in total** | **≈ 70 KB** |
|
| 283 |
+
|
| 284 |
+
That leaves us about 186 KB of the 256 KB limit for everything else. The peak
|
| 285 |
+
activation is only 960 bytes, at S1's output; the arena is mostly kernel scratch
|
| 286 |
+
and alignment.
|
| 287 |
+
|
| 288 |
+
### Ring Buffers & Streaming State
|
| 289 |
+
|
| 290 |
+
We keep this state between steps, inside the TFLM arena as resource variables,
|
| 291 |
+
so we allocate nothing separately.
|
| 292 |
+
|
| 293 |
+
| Buffer | Shape | Bytes |
|
| 294 |
+
|---|---|---:|
|
| 295 |
+
| S1 time history | 2 frames × 40 | 80 |
|
| 296 |
+
| S2a time history | stride 3 over kernel 3, nothing to keep | 0 |
|
| 297 |
+
| B1 ring, d = 1 | 4 × 48 | 192 |
|
| 298 |
+
| B2 ring, d = 1 | 4 × 48 | 192 |
|
| 299 |
+
| B3 ring, d = 2 | 8 × 48 | 384 |
|
| 300 |
+
| B4 ring, d = 2 | 8 × 48 | 384 |
|
| 301 |
+
| B5 ring, d = 3 | 12 × 48 | 576 |
|
| 302 |
+
| B6 ring, d = 3 | 12 × 48 | 576 |
|
| 303 |
+
| **Total** | | **2,384** |
|
| 304 |
+
|
| 305 |
+
A dilated causal depthwise convolution needs (k − 1) × d × C bytes of history
|
| 306 |
+
at int8.
|
| 307 |
+
|
| 308 |
+
### Flash
|
| 309 |
+
|
| 310 |
+
| Item | Bytes |
|
| 311 |
+
|---|---:|
|
| 312 |
+
| int8 weights | 31,472 |
|
| 313 |
+
| int32 biases, 689 channels × 4 | 2,756 |
|
| 314 |
+
| Per-channel scales, 689 × 4 | 2,756 |
|
| 315 |
+
| FlatBuffer structure and metadata | ≈ 4,096 |
|
| 316 |
+
| Mel filterbank and Hann window tables | ≈ 3,072 |
|
| 317 |
+
| **Total** | **≈ 44 KB** |
|
| 318 |
+
|
| 319 |
+
## Post-Processing & Trigger Logic
|
| 320 |
+
|
| 321 |
+
<p align="center">
|
| 322 |
+
<img src="assets/trigger.png" alt="Illustration: the smoothed score stays low while Utho Kikkar is said, rises once it ends, and crosses the threshold 60 ms later, which wakes the board; a second peak inside the 1 s refractory period is ignored" width="100%">
|
| 323 |
+
</p>
|
| 324 |
+
<p align="center"><sub>An illustration of the rule, not a recording.</sub></p>
|
| 325 |
+
|
| 326 |
+
| Step | Setting |
|
| 327 |
+
|---|---|
|
| 328 |
+
| Model output | one probability per 30 ms step |
|
| 329 |
+
| Smoothing | average of the last 3 steps, 90 ms |
|
| 330 |
+
| Threshold τ | 0.7, picked from the DET curve of the int8 model |
|
| 331 |
+
| Refractory | 1 s after a wake-up |
|
| 332 |
+
| Phrase end to wake-up | 60 ms: up to 30 ms for the step that holds the end of the phrase, then one more step |
|
| 333 |
+
|
| 334 |
+
The wake-up comes quickly because of how we labelled the model. We turn its
|
| 335 |
+
target on one step *before* the phrase ends, so by the time the step holding the
|
| 336 |
+
end is done, two of the three steps in the average are already high, and one
|
| 337 |
+
more step takes it over τ. Computing a step takes a millisecond or less, so it
|
| 338 |
+
barely adds to the 60 ms.
|
| 339 |
+
|
| 340 |
+
Quantisation moves the operating point, so we always pick the threshold on the
|
| 341 |
+
int8 model and never carry it over from the float one. If false activations
|
| 342 |
+
will not come down, the cheapest remaining lever we have is two or three frames
|
| 343 |
+
of lookahead, paid for directly in latency.
|
| 344 |
+
|
| 345 |
+
## Training Methodology & Supervision
|
| 346 |
+
|
| 347 |
+
<p align="center">
|
| 348 |
+
<img src="assets/supervision.png" alt="One label per 30 ms step: for Utho Kikkar only the six steps around the end of the phrase are labelled 1, and mid-phrase steps are 0; wrong order and half a phrase are 0 throughout" width="100%">
|
| 349 |
+
</p>
|
| 350 |
+
|
| 351 |
+
**Phrase-completion supervision.** We built the head as a per-step detector,
|
| 352 |
+
not a clip classifier. We label only the six steps from one before the end of
|
| 353 |
+
the phrase to four after it, about 180 ms, as 1. We label every other step 0,
|
| 354 |
+
including the middle of the phrase, and partial or reversed phrases 0
|
| 355 |
+
throughout. That is what teaches the model word order, and it makes the firing
|
| 356 |
+
delay equal to the smoothing window. We get the phrase end from energy-based
|
| 357 |
+
silence trimming on recordings, or straight from the synthesiser for TTS clips,
|
| 358 |
+
and when we speed a clip up or slow it down, we move its end by the same factor.
|
| 359 |
+
|
| 360 |
+
| Frames | Label |
|
| 361 |
+
|---|---|
|
| 362 |
+
| Steps from t_end − 1 to t_end + 4, about 180 ms | 1 |
|
| 363 |
+
| Every other step, mid-phrase included | 0 |
|
| 364 |
+
| Partial phrase, *utho* or *kikkar* alone | 0 throughout |
|
| 365 |
+
| Reversed order, *kikkar utho* | 0 throughout |
|
| 366 |
+
|
| 367 |
+
**Loss and selection.** We use per-step weighted binary cross-entropy.
|
| 368 |
+
Positives are about 6 steps in 300, but a positive weight of 50 over-fires, so
|
| 369 |
+
we start it at 8; we weight confusable negatives 8 and easy ones 1. We choose
|
| 370 |
+
checkpoints on the fewest false activations per hour of held-out continuous
|
| 371 |
+
speech first, and on recall only among those that meet the false-activation
|
| 372 |
+
target, never on accuracy.
|
| 373 |
+
|
| 374 |
+
**Positives.** We use about 2,000 real recordings, split by speaker so that
|
| 375 |
+
the model never hears validation and test speakers in training. On top of that,
|
| 376 |
+
we add several thousand synthetic renditions from AI4Bharat Indic-TTS, IndicF5,
|
| 377 |
+
Indic Parler-TTS, MMS-TTS in Punjabi and Hindi, and Piper, with varied prosody
|
| 378 |
+
and gaps between the two words. We oversample the real recordings so they carry
|
| 379 |
+
25 to 40% of the positive signal, otherwise the model learns vocoder artefacts.
|
| 380 |
+
|
| 381 |
+
**Confusable negatives.**
|
| 382 |
+
|
| 383 |
+
| Kind | Examples |
|
| 384 |
+
|---|---|
|
| 385 |
+
| Partial phrase | *utho*, *kikkar* |
|
| 386 |
+
| Wrong order | *kikkar utho* |
|
| 387 |
+
| Sounds like *kikkar* | kukkad, kukkar, chakkar, takkar, shakkar, nikkar, fikar, Makkar, Thakkar, kirkiri |
|
| 388 |
+
| Sounds like *utho* | utha, uthao, uthe, utha lo, uncha |
|
| 389 |
+
| Natural continuations | utho ji, utho beta, utho jaldi |
|
| 390 |
+
| Across word boundaries | "…jhoota kikar…", "…peeche kikar…" |
|
| 391 |
+
| English in the middle | kicker, quicker, sticker, liquor, auto, photo |
|
| 392 |
+
|
| 393 |
+
**Background negatives.** We use continuous Hindi and Punjabi speech from
|
| 394 |
+
Common Voice, IndicVoices and Shrutilipi, plus sounds from around the house, and
|
| 395 |
+
stream them as long segments so that training sees what the board hears.
|
| 396 |
+
|
| 397 |
+
**Augmentation.** We apply room impulse responses (OpenSLR-28, BUT ReverbDB) at
|
| 398 |
+
different distances; noise from MUSAN, DEMAND and ESC-50 at 0 to 20 dB SNR; gain from −20
|
| 399 |
+
to 0 dBFS; speed 0.9 to 1.1; pitch ±2 semitones; microphone response tilt; mild
|
| 400 |
+
clipping; frequency masking. We keep time masking light, because the labels
|
| 401 |
+
depend on timing.
|
| 402 |
+
|
| 403 |
+
**Hard negatives.** We train, stream the model over more than 10 hours of
|
| 404 |
+
Hindi, Punjabi and English speech, collect every false trigger as a new
|
| 405 |
+
negative, and train again, two or three times over.
|
| 406 |
+
|
| 407 |
+
**Streaming.** We train with causal convolutions over long 8 to 10 s chunks,
|
| 408 |
+
which is fast and parallel, then deploy the same weights running step by step
|
| 409 |
+
on ring buffers. We check that the streaming and full-chunk outputs agree
|
| 410 |
+
within 1e-3 before quantising.
|
| 411 |
+
|
| 412 |
+
**Quantisation.** We quantise after training, with a representative set of
|
| 413 |
+
real streaming features rather than synthetic clips, and fold batch norm into
|
| 414 |
+
the convolutions before export.
|
| 415 |
+
|
| 416 |
+
| Tensor | Scheme |
|
| 417 |
+
|---|---|
|
| 418 |
+
| Activations | int8, asymmetric, per tensor |
|
| 419 |
+
| Weights | int8, symmetric, per channel |
|
| 420 |
+
| Bias | int32 |
|
| 421 |
+
| Final sigmoid | float32, on a single number |
|
| 422 |
+
|
| 423 |
+
## Hardware Profiling & Benchmarks
|
| 424 |
+
|
| 425 |
+
<table>
|
| 426 |
+
<tr>
|
| 427 |
+
<td align="center" width="50%"><img src="assets/board-stm32n657.jpg" alt="STM32N6570-DK with the kikkar flower in full bloom on its display" width="100%"></td>
|
| 428 |
+
<td align="center" width="50%"><img src="assets/board-esp32.jpg" alt="ESP32 board with an I2S microphone on perfboard" width="100%"></td>
|
| 429 |
+
</tr>
|
| 430 |
+
<tr>
|
| 431 |
+
<td align="center"><b>Premium:</b> STM32N657, Ethernet and an 800 × 480 display</td>
|
| 432 |
+
<td align="center"><b>Budget:</b> ESP32 and an I2S microphone, on Wi-Fi</td>
|
| 433 |
+
</tr>
|
| 434 |
+
</table>
|
| 435 |
+
|
| 436 |
+
<p align="center">
|
| 437 |
+
<img src="assets/on-device.png" alt="Idle CPU: STM32N657 0.5%, ESP32 4%, limit 10%. RAM used: STM32N657 150 KB, ESP32 190 KB, limit 256 KB. Handoff latency: STM32N657 80 ms, ESP32 90 ms." width="100%">
|
| 438 |
+
</p>
|
| 439 |
+
|
| 440 |
+
| | STM32N657, premium | ESP32, budget | SIH limit |
|
| 441 |
+
|---|---|---|---|
|
| 442 |
+
| CPU while idling in continuous listening | **0.5%** | **4%** | under 10% |
|
| 443 |
+
| RAM used | **150 KB** | **190 KB** | under 256 KB |
|
| 444 |
+
| Latency, keyword end to audio at the ASR server | **80 ms** | **90 ms** | as low as possible |
|
| 445 |
+
|
| 446 |
+
These are our numbers for the whole application, networking and display
|
| 447 |
+
included, not the model alone. Of the 80 ms, 60 ms is our model making sure; the other
|
| 448 |
+
20 ms is the board getting the first audio to the server over Ethernet. Wi-Fi
|
| 449 |
+
takes 30 ms for the same step on the ESP32.
|
| 450 |
+
|
| 451 |
+
### Core Utilization & RTOS Tasks
|
| 452 |
+
|
| 453 |
+
On an ESP32-S3 at 240 MHz with ESP-NN int8 kernels:
|
| 454 |
+
|
| 455 |
+
| Task | Rate | Share of one core |
|
| 456 |
+
|---|---|---|
|
| 457 |
+
| FFT, mel and CMS | 100 a second | ≈ 0.6% |
|
| 458 |
+
| Inference | 33.3 a second | 0.7 to 2.6% |
|
| 459 |
+
| I2S, DMA and housekeeping | | ≈ 0.5% |
|
| 460 |
+
| **Idle listening in total** | | **≈ 2 to 4%** |
|
| 461 |
+
|
| 462 |
+
We run capture and inference as separate FreeRTOS tasks pinned to different cores.
|
| 463 |
+
A classic ESP32 has no vector unit and runs the inference about three times
|
| 464 |
+
slower, which still fits well inside 10% of a core.
|
| 465 |
+
|
| 466 |
+
## Target Firmware Integration (STM32 & ESP32)
|
| 467 |
+
|
| 468 |
+
On the ESP32 we run the model under TensorFlow Lite for Microcontrollers, with
|
| 469 |
+
int8 kernels from ESP-NN. Its 2.4 KB of streaming state lives inside the TFLM
|
| 470 |
+
arena as resource variables, so we have nothing extra to allocate. Size the
|
| 471 |
+
arena from `arena_used_bytes()` measured on the device, not from the estimate
|
| 472 |
+
above.
|
| 473 |
+
|
| 474 |
+
On the STM32N657 we do not use TFLM at all. We wrote a small exporter that turns
|
| 475 |
+
this `.tflite` into a flat list of 23 operations, and our firmware runs them with
|
| 476 |
+
its own int8 kernels, using Helium vector instructions for the dot products. It keeps the
|
| 477 |
+
same 2,384 bytes of history in rings, one per layer that looks back in time,
|
| 478 |
+
and the whole model works inside a 5.3 KB arena. Our firmware, the exporter,
|
| 479 |
+
the flower and the streaming pipeline are on [GitHub](https://github.com/SherTheCoder/Folklore).
|
| 480 |
+
|
| 481 |
+
## Field Testing & Edge Constraints
|
| 482 |
+
|
| 483 |
+
- **Test it on real people in real rooms,** and pick the threshold there, on
|
| 484 |
+
the int8 model.
|
| 485 |
+
- **It knows one phrase.** Ours is not a general speech model, and our model cannot
|
| 486 |
+
currently tell who is speaking.
|
| 487 |
+
- **The front end has to match.** The running-mean normalisation is part of
|
| 488 |
+
the input, and it needs its first half second after boot to settle.
|
| 489 |
+
- **Privacy is the point of our design.** We keep all audio on the board
|
| 490 |
+
until the wake word is confirmed.
|
| 491 |
+
|
| 492 |
+
## Licence
|
| 493 |
+
|
| 494 |
+
We release it under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
| 495 |
+
licence.
|
| 496 |
+
|
| 497 |
+
## Citation
|
| 498 |
+
|
| 499 |
+
```bibtex
|
| 500 |
+
@misc{teamfolklore2026kikkarkws,
|
| 501 |
+
title = {Kikkar KWS: a 44 KB streaming wake-word model for Utho Kikkar},
|
| 502 |
+
author = {{Team Folklore}},
|
| 503 |
+
year = {2026},
|
| 504 |
+
howpublished = {\url{https://huggingface.co/SherTheCoder/TeamFolklore_Model}}
|
| 505 |
+
}
|
| 506 |
+
```
|
| 507 |
+
|
| 508 |
+
## Made by
|
| 509 |
+
|
| 510 |
+
We are Team Folklore, and we made this for Smart India Hackathon 2026. Our
|
| 511 |
+
firmware, flower and streaming pipeline are on [GitHub](https://github.com/SherTheCoder/Folklore);
|
| 512 |
+
our training data is [SherTheCoder/TeamFolklore_UthoKikkar](https://huggingface.co/datasets/SherTheCoder/TeamFolklore_UthoKikkar).
|
assets/architecture.png
ADDED
|
assets/banner.png
ADDED
|
Git LFS Details
|
assets/board-esp32.jpg
ADDED
|
Git LFS Details
|
assets/board-stm32n657.jpg
ADDED
|
Git LFS Details
|
assets/compute.png
ADDED
|
assets/features.png
ADDED
|
assets/memory.png
ADDED
|
Git LFS Details
|
assets/on-device.png
ADDED
|
assets/supervision.png
ADDED
|
assets/temporal-block.png
ADDED
|
assets/trigger.png
ADDED
|
model_version0-2.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2c269b3b71d4d32297b463ad8aee02826513516f05e488fe61953b35e68676e3
|
| 3 |
+
size 45728
|