TCS Pune

Tiny Keyword Spotting on Cortex-M

Advanced · 7–10 hours

Tiny Keyword Spotting on Cortex-M

Recognise a small command vocabulary while measuring false accepts, privacy exposure and real-time memory use.

Arduino Nano 33 BLE Sense / STM32 Cortex-MDigital MEMS microphoneTensorFlow Lite Micro or Edge Impulse C++ library

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

  1. Use consented recordings from multiple speakers
  2. Include unknown speech, silence and representative noise
  3. Separate speakers between training and test where possible
  4. Fix sample rate, clip length and amplitude policy
  5. Do not retain unnecessary raw voice data

Training and validation pipeline

  1. Verify audio clipping and DC offset
  2. Create identical spectral preprocessing for training/device
  3. Review per-class precision, recall and confusion
  4. Quantise and measure model-size/accuracy change
  5. Test quiet, near-field and noisy conditions
  6. Set confidence, smoothing and refractory time

Model deployment procedure

  1. Allocate ring buffers and tensor arena statically
  2. Run feature extraction in bounded frames
  3. Use only required TFLM operators
  4. Measure worst-case inference and buffer headroom
  5. Apply confidence smoothing and unknown class
  6. Disable or indicate capture according to privacy policy

Memory and performance targets

MetricTargetUnitWhy it matters
Validation accuracy>= 82%Multi-speaker, noisy held-out evaluation
Flash usage<= 900KBLeaves firmware update margin
Peak RAM / arena<= 240KBIncludes audio buffers and tensors
Inference latency<= 45msMust keep pace with feature frames

Deployment checkpoints

CheckExpected resultEvidence
Audio inputSample rate and amplitude match trainingCaptured waveform
Unknown speechUnlisted words reject reliablyTest log
Noise testFalse accepts remain below chosen limitConfusion/event log
Continuous runNo buffer overrun for 30 minutesCounter 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

SymptomLikely causeCorrective action
No commands detectedMicrophone format/sample rate mismatchVerify raw waveform and driver format
Many false acceptsMissing unknown/noise coverageExpand representative negative data
Audio gapsFeature/inference path misses deadlinesProfile each stage and reduce model/features
Build too largeToo many operators or float kernelsUse 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 measurements

Interview and viva questions

  1. Why should speakers be separated across dataset splits?
  2. What is an unknown class?
  3. Why use score smoothing and refractory time?
  4. How do audio buffers contribute to peak RAM?
  5. 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.

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA