Tiny Keyword Spotting on Cortex-M
Recognise a small command vocabulary while measuring false accepts, privacy exposure and real-time memory use.
Learning objectives
- Build balanced audio classes with noise coverage
- Generate consistent spectral features
- Quantise and deploy a small audio model
- Measure continuous-stream latency and false accepts
Prerequisites
- Digital audio sampling
- FFT or mel-filterbank concepts
- C/C++ embedded build workflow
Dataset and labelling plan
- Use consented recordings from multiple speakers
- Include unknown speech, silence and representative noise
- Separate speakers between training and test where possible
- Fix sample rate, clip length and amplitude policy
- Do not retain unnecessary raw voice data
Training and validation pipeline
- Verify audio clipping and DC offset
- Create identical spectral preprocessing for training/device
- Review per-class precision, recall and confusion
- Quantise and measure model-size/accuracy change
- Test quiet, near-field and noisy conditions
- Set confidence, smoothing and refractory time
Model deployment procedure
- Allocate ring buffers and tensor arena statically
- Run feature extraction in bounded frames
- Use only required TFLM operators
- Measure worst-case inference and buffer headroom
- Apply confidence smoothing and unknown class
- Disable or indicate capture according to privacy policy
Memory and performance targets
| Metric | Target | Unit | Why it matters |
|---|---|---|---|
| Validation accuracy | >= 82 | % | Multi-speaker, noisy held-out evaluation |
| Flash usage | <= 900 | KB | Leaves firmware update margin |
| Peak RAM / arena | <= 240 | KB | Includes audio buffers and tensors |
| Inference latency | <= 45 | ms | Must keep pace with feature frames |
Deployment checkpoints
| Check | Expected result | Evidence |
|---|---|---|
| Audio input | Sample rate and amplitude match training | Captured waveform |
| Unknown speech | Unlisted words reject reliably | Test log |
| Noise test | False accepts remain below chosen limit | Confusion/event log |
| Continuous run | No buffer overrun for 30 minutes | Counter and timing evidence |
Inference code
audio_ring_push(new_samples);
while (feature_frame_ready()) {
make_features(audio_ring, input_tensor);
invoke();
update_smoothed_scores(output_tensor);
if (stable_command_above_threshold()) emit_command();
}Troubleshooting
| Symptom | Likely cause | Corrective action |
|---|---|---|
| No commands detected | Microphone format/sample rate mismatch | Verify raw waveform and driver format |
| Many false accepts | Missing unknown/noise coverage | Expand representative negative data |
| Audio gaps | Feature/inference path misses deadlines | Profile each stage and reduce model/features |
| Build too large | Too many operators or float kernels | Use int8 model and minimal resolver |
Safety, privacy and model limits
- Get consent before recording voices.
- Do not upload private conversations to training services.
- Provide a visible indication when audio capture is active.
- Never use a classroom keyword model for security authentication.
Measured deployment profile
Log in to record deployment measurementsInterview and viva questions
- Why should speakers be separated across dataset splits?
- What is an unknown class?
- Why use score smoothing and refractory time?
- How do audio buffers contribute to peak RAM?
- Which metrics matter when false activation is costly?
Lesson notes
Responsible TinyML workflow
Keep raw data, preprocessing, model version, compiler options and measured device results together. A desktop accuracy score does not prove embedded performance. Validate representative unseen samples on the actual target and define an explicit fallback for low confidence or out-of-distribution input.
Deployment evidence
Record the dataset split, confusion matrix, exported model hash, firmware build, board revision, peak memory, average and worst-case latency, power conditions and failures. Never treat an educational classifier as a safety-certified decision system.
