A local, script-driven alternative to trainer/microwakeword_trainer_colab.ipynb
that anyone can run.
It runs the same underlying pipeline as the Colab notebook — synthesize wake
word audio with Piper TTS, augment it with background noise and room
impulse responses, turn that into spectrogram features, and train a
microWakeWord model — as a
plain Python CLI you run on your own machine instead of in a Colab VM.
- Python 3.11 (due to microWakeWord dependencies, python version must be either 3.11 or 3.10)
- Later distributions of Ubuntu/Debian (26.04, Trixie) ship with Python 3.14. Either Deadsnakes PPA or pyenv will allow easy side by side installations of 3.14 and 3.11. Personal recommendation is pyenv. Either way you'll be using a virtual environment to handle dependencies, but I find pyenv a bit more straight forward by simply configuring py version on a folder/project level and proceeding without needing to actually activate a .venv.
git- ~30-40 GB free disk per workspace (background/negative audio datasets are
the bulk of it: Audioset alone is several GB per split).
- After downloading audio datasets, multiple models can be trained without downloading again using the same workspace.
- An NVIDIA GPU is optional but strongly recommended for training speed - see the GPU note below. CPU-only works, just slowly (10,000 training steps can take an hour or more on a laptop CPU). A GPU can be used both via WSL and in native Linux, but not using native Windows (Windows is CPU only)
- Native Windows, via Surface Laptop Studio 2 CPU only Using CPU only on Windows or WSL, a training run (downloading all audio and training) takes about 70-80 minutes. About half of that is downloading audio, which is only required once. So multiple models takes ~40 minutes each.
- WSL2, via Surface Laptop Studio 2 with Nvidia 4050 GPU I do not yet have the 4050 working with WSL on the Surface Laptop. I'll update benchmark once I do but I'd expect a substantially faster training time. Probably less than 15 minutes per model.
- Native Ubuntu 26.04, via AMD 9950X and a 2080TI Using native Linux with Nvidia drivers version 595 takes about 30-40 minutes, including download times. After audio download, models can be produced in about 5 minutes each.
- Fixes a missing step. The notebook's training-config cell references a
generated_features_output_dirvariable that's never defined anywhere - the cell that actually turns augmented clips into the spectrogram features microWakeWord trains on is absent.build_features.py(thebuild-featurescommand) is that missing step, ported from microWakeWord's own upstreamnotebooks/basic_training_notebook.ipynb. - Supports multiple phonetic spellings of the same wake word
(
wake_word.additional_phoneticsin the config) - each spelling gets its own full batch of generated samples, which generally improves the model's robustness to different pronunciations. - Resumable, idempotent steps. Every step checks what it's already done and skips it, so you can re-run the same command after an interruption (or after changing a downstream config value) without redoing finished work.
- Routes around several environment-specific dependency issues (see Troubleshooting below) that the original notebook doesn't have to deal with, since Colab's VM image and package versions are fixed at the time the notebook was written.
- Menu-driven by default.
python -m trainer.local.cli(no arguments) launches an interactive menu that runs every step below in order and only stops to ask you something when a step genuinely needs a human decision - see Running the pipeline.
setup → clone/install microWakeWord + piper-sample-generator, download the Piper voice model
preview-word → generate 1 sample, listen to it, adjust phonetic spelling
generate-samples → generate the full batch of synthetic wake word samples
download-data → download RIR / Audioset / FMA background audio + pre-built negative feature sets
preview-augment → (optional) generate 1 augmented clip to sanity-check augmentation settings
build-features → augment samples, build train/validation/test spectrogram feature mmaps
train → train the model, quantize + convert to a streaming .tflite
export → copy the .tflite + write an ESPHome V2 model manifest .json
Everything a run produces - cloned repos, downloaded datasets, generated
samples, feature mmaps, trained checkpoints, and the final exported model -
lives under one workspace/ directory (configurable), so different wake
words can have entirely independent workspaces.
TensorFlow dropped native GPU support on Windows after version 2.10, and
microWakeWord requires tensorflow>=2.18. That means:
- Native Windows (PowerShell, no WSL): training runs CPU-only, no matter what GPU you have.
- WSL2 (Windows Subsystem for Linux): TensorFlow can use an NVIDIA GPU normally, via the same driver passthrough any other WSL2 CUDA workload uses.
- Native Linux (Tested Ubuntu 26.04): Provided that both Nvidia drivers and CUDA drivers are installed prior to installing TensorFlow with CUDA, GPU should work fine.
The commands below are the same for Windows and WSL; only the initial environment setup differs. Pick whichever section matches how you want to run it. The commands for Native Linux are identical to WSL, save for driver installation
-
Install Python 3.11 and Git if you don't already have them.
-
From the repo root, in PowerShell:
python -m venv .venv .venv\Scripts\Activate.ps1 pip install -r trainer\requirements.txt
-
Create your wake word config:
Copy-Item trainer\wakeword_config.example.yaml trainer\wakeword_config.yamlEdit
trainer\wakeword_config.yaml- at minimum setwake_word.phoneticandwake_word.friendly_name. See the comments intrainer\wakeword_config.example.yamlfor what every other field does. -
Launch the interactive menu - it installs the rest of the toolchain (microWakeWord, piper-sample-generator, the Piper voice checkpoint) as its first step, then walks you through the rest of the pipeline. See Running the pipeline below.
python -m trainer.local.cli
-
Either Install WSL2 with Ubuntu, or install Ubuntu directly
To install Ubuntu for WSL2 for Windows, from a PowerShell prompt:
wsl --install -d Ubuntu
Reboot if prompted, then open an Ubuntu WSL terminal once to finish first-time setup (creates your Linux user account).
-
WSL2: Install an NVIDIA driver on the Windows side only. Download the latest driver from nvidia.com and install it normally on Windows. Do not install a separate NVIDIA Linux driver inside WSL - WSL2 shares the Windows host's driver via GPU passthrough, and installing one inside Ubuntu will break it.
-
OR: Native Ubuntu: Install NVIDIA and CUDA drivers .
To install Nvidia drivers on Ubuntu, start by installing the Ubuntu proprietary driver installer:
sudo apt-get install ubuntu-drivers-common
Verify that an Nvidia GPU is installed in the system
ubuntu-drivers devices
You should see an output of drivers compatible with the system, along with the compatible device itself (see below. I selected the 595 drivers for training)
Install one of the compatible drivers via ubuntu-drivers (I chose 595)
sudo ubuntu-drivers install nvidia-driver-595Reboot after Nvidia driver install
sudo rebootInstall CUDA toolkit after reboot
sudo apt install nvidia-cuda-toolkit -yVerify the GPU and CUDA is visible inside Linux/WSL:
nvidia-smiMake sure this prints your GPU, Nvidia driver version, and CUDA toolkit version version. (See below) If it fails, or fails to print CUDA version, reinstall as necessary
-
Install build tools and Python 3.11 inside Ubuntu (WSL and Native Ubuntu):
*Remember this needs to be python 3.11. The below will work with older versions of Ubuntu or Debian, but for newer versions that ship with 3.12+, make sure to use the DeadSnakes repo for Ubuntu to install 3.11 side by side with the modern Ubuntu/Debian version.
Alternatively, and my personal recommendation, is to install pyenv and pyenv-virtualenv, and use pyenv to install 3.11*.
An AI overview of installing Python 3.11 on Ubuntu 26.04 using PyEnv can be found here
For older versions of Ubuntu (22.04, 24.04?), you can install via apt:
sudo apt update sudo apt install -y python3 python3-venv python3-pip build-essential git
-
Clone the repo.
git clone https://github.com/JohnnyPrimus/MicroWakeWordV2Trainer.git ~/MicroWakeWordV2Trainer -
Option 1) Set up the Python environment (native Python install):
cd ~/MicroWakeWordV2Trainer python3 -m venv .venv source .venv/bin/activate pip install -r trainer/requirements.txt
Option 2) Setup pyenv environment:
cd ~/MicroWakeWordV2Trainer pyenv local 3.11 pip install -r trainer/requirements.txt
-
Create your wake word config (same as the Windows instructions):
cp trainer/wakeword_config.example.yaml trainer/wakeword_config.yaml
Edit wakeword_config.yaml - at minimum
wake_word.phoneticandwake_word.friendly_name. -
Run setup, then explicitly install the CUDA-enabled TensorFlow extras (microWakeWord's own dependency list just says
tensorflow, which alone doesn't pull in the CUDA/cuDNN wheels):python3 -m trainer.local.cli setup pip install "tensorflow[and-cuda]" -
Verify TensorFlow sees the CPU:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"You should see a no error and a tensor shown at the end of the output. (See below)

9.1 Optional: Verify TensorFlow sees the GPU:
If you either have GPU passthrough via WSL working, or have installed both the Nvidia and CUDA drivers, check to ensure TensorFlow can see the GPU
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"You should see a PhysicalDevice entry with device_type='GPU'. If the
list is empty, re-check steps 2-3 and step 8's tensorflow[and-cuda]
install. (See below)

- Launch the interactive menu for the rest of the pipeline - see
Running the pipeline below. Its first step re-runs
setup, which is safe here too - it won't touch the CUDA-enabled TensorFlow you just installed in step 8.
If you're using a GPU with limited VRAM (e.g. a laptop GPU with 6-8 GB), and training
fails with an out-of-memory error, lower training.batch_size in the
config (default 128).
The recommended way to run everything is the interactive menu:
python3 -m trainer.local.cli
(On Windows: python rather than python3.)
It walks through every step below in order -
setup, preview-word, generate-samples, download-data, preview-augment,
build-features, train, export - running each one automatically, and only
stops at points that decisions are optional or required, for example listening to a
preview and confirming it sounds right (see sample_models directory for examples), choosing
whether to retrain over an existing checkpoint, picking a probability
cutoff after looking at the ROC results, and entering export metadata.
Everything else just runs straight through. If trainer/wakeword_config.yaml
doesn't exist yet, it offers to create one interactively on first launch.
From the main menu you can also jump in and re-run starting from any
individual step (e.g. after editing the config).
Pass --config <path> (before or after the subcommand) to point at a
different config file - e.g. to train several wake words side by side, since
each config's workspace directory is independent.
Every step is also available as its own python -m trainer.local.cli <command> for scripting a single step directly, documented below. Both
forms are equivalent - the menu just makes things easier. Every step is safe to re-run either way: it checks
what it's already produced and skips finished work.
-
Check the phonetic spelling by generating one sample and listening to it:
python -m trainer.local.cli preview-wordListen to
workspace/preview_samples/<friendly_name>/<slug>/0.wav. Adjustwake_word.phoneticin the config until it sounds right, then re-run. -
Generate the full sample batch:
python -m trainer.local.cli generate-samplesGenerates
piper.max_samplessamples forwake_word.phonetic, plus a full batch for each entry inwake_word.additional_phonetics(see Multiple phonetic spellings below). Controlled bypiper.max_samples/piper.batch_sizein the config - this is the step to revisit first when trying to improve a model: more samples, more phonetic variants, or differentlength_scales/noise_scalesall help. -
Download background/negative audio data (RIRs, Audioset, FMA, and pre-generated negative spectrogram sets). This is the slowest step - expect 30-45+ minutes and several GB of disk:
python -m trainer.local.cli download-dataLicense note: this data mixes several licenses and usage restrictions. Treat models trained with it as personal-use only unless you check the license of each source for commercial use.
-
(Optional) Preview an augmented clip:
python -m trainer.local.cli preview-augmentWrites
augmented_clip_preview.wavin the current directory, so you can listen to what the augmentation pipeline (background noise mixing, RIR, pitch/gain/EQ perturbation) actually sounds like. -
Build spectrogram features (augments samples, builds the training/validation/testing feature mmaps):
python -m trainer.local.cli build-featuresRe-run this after adding samples (a new phonetic spelling, more generated samples, etc.) - it globs
generated_samples/<name>/**/*.wavfresh each time it needs to rebuild a split. -
Train:
python -m trainer.local.cli trainHyperparameters live under
training:in the config (training steps, class weights, learning rate, model architecture args, etc.) - these matter a lot for model quality, especially for very short or long wake words. This step also quantizes and converts the best checkpoint to a streaming.tflite, and writes real test results toworkspace/trained_models/<name>/tflite_stream_state_internal_quant/tflite_streaming_roc.txt(see Choosing a probability cutoff).Resuming: if training is interrupted, just run the same command again - it restores the last checkpoint's weights automatically. Note that microWakeWord's own training script always re-runs the full
training_stepsbudget from step 0 on resume (it doesn't remember how many steps it had already done), so a resumed run isn't "picking up where it left off" step-count-wise, even though it's warm-started from good weights. If the model already looks converged (check theStep N (nonstreaming): Validation: ...log lines -average_viable_recallnear 1.0 with 100% precision is a good sign), you can skip straight to converting the existing best checkpoint instead of retraining:python -m trainer.local.cli train --no-train -
Export for ESPHome:
python -m trainer.local.cli export --probability-cutoff 0.9Writes
workspace/exported_models/<name>/<name>.tfliteand a matching.jsonV2 model manifest (see the ESPHome docs and example manifests). Flags:--probability-cutoff(default 0.5),--tensor-arena-size(default 30000),--author,--website. Raise--tensor-arena-sizeif ESPHome fails to load the model.
Steps 3, 5, and 6 can also be run together once setup/samples are done:
python -m trainer.local.cli all
Add alternate phonetic spellings of the same wake word to broaden the model's coverage of how it might actually be pronounced:
wake_word:
phonetic: "hey wabi"
friendly_name: "hey_wabi"
additional_phonetics:
- "hey wahbee"
- "hey wah-bee"generate-samples generates a full piper.max_samples-sized batch for
each spelling, into its own subdirectory under generated_samples/<name>/.
build-features picks up every spelling's samples automatically. In
testing, adding a second spelling to an already-good model did lower the
best achievable false-rejection-rate-at-zero-false-alarms slightly (broader
phonetic coverage makes the classification task harder) - this is a real
accuracy/robustness tradeoff, not a bug, so check
tflite_streaming_roc.txt after retraining rather than assuming more
spellings is strictly better for your specific wake word.
After train, workspace/trained_models/<name>/tflite_stream_state_internal_quant/tflite_streaming_roc.txt
lists, for a range of cutoffs: frr (false-rejection rate - how often a
real wake word utterance is missed) and faph (estimated false alarms per
hour on ambient/negative audio). For a voice assistant wake word, false
alarms are usually more annoying than an occasional missed trigger, so
picking the lowest cutoff with faph=0.000 is a reasonable default -
that's what export's --probability-cutoff flag should be set to. Lower
the cutoff (accepting some false alarms) if it feels unresponsive in
practice; raise it if it triggers on background noise or speech.
Several dependency issues showed up getting this running on Windows that
you likely won't hit again since setup_env.py already works around them,
but are worth knowing about if something still breaks:
ModuleNotFoundError: No module named 'torchcodec'/ImportError: ... please install 'torchcodec': newerdatasetslibrary versions requiretorchcodec(which itself needs a matching system FFmpeg install) just to decode/encode audio, even for local files. We pindatasets<4.0and don't usedatasetsat all indownload_datasets.py, specifically to avoid this. If you see this error, something reinstalled a newerdatasets- re-runpip install "datasets<4.0".ModuleNotFoundError: No module named 'piper_train': piper-sample-generator's PyPI package only ships thepiper_sample_generatormodule, not the siblingpiper_trainmodule its multi-speaker generator code path imports.setupclones the full repo instead of just pip-installing the package, andgenerate_samples.pyputs the repo root onPYTHONPATH.AttributeError: module 'audiomentations' has no attribute 'AddColorNoise': piper-sample-generator pinsaudiomentations==0.33.0, which predates that transform, but microWakeWord's augmentation needs it.setupinstalls a neweraudiomentationsafterward, overriding that pin (safe - we never use piper-sample-generator's own.augmentmodule).ModuleNotFoundError: No module named 'pkg_resources':webrtcvadstill doesimport pkg_resourcesat load time;setuptools>=81removed that shim.setuppinssetuptools<81.tensorflow.python.summary.tb_summary.TBNotInstalledError: microWakeWord's training script logs metrics viatf.summary.scalar, which needstensorboardinstalled even though nothing views the logs.setupinstalls it.- A rebuilt
build-featuressplit turns out empty:RaggedMmap.from_generatorcreates its output directory before writing any data, so a crash mid-build can leave an empty-but-existing directory.build_features.pychecks for the actual data file, not just the directory, before deciding a split is already done - if you're on an older checkout without that fix, deleteworkspace/generated_augmented_features/<name>/<split>/and re-run.