Skip to content

Latest commit

 

History

History

dataset

How to generate a dataset for custom wakeword

Generating a dataset for a custom wakeword requires three steps:

  1. Generating raw audio dataset that howl can load from open datasets
  2. Generate orthographic transcription alignments for each audio file.
  3. Attach the alignment to the raw audio dataset generated in step 1.

In the example that follows, we describe the process of generating a dataset for the word, "fire".

  1. Download a supported data source. We recommend Common Voice for its breadth and free license.

  2. To provide transcription alignment for the data, we use Montreal Forced Aligner (MFA) along with an English pronunciation dictionary. We have written a script that download them under the repo

./download_mfa.sh
  1. Create raw audio datasets containing the keyword for howl from open audio datasets: note that 5% is sufficient when generating negative dataset from common-voice dataset
VOCAB='["fire"]' INFERENCE_SEQUENCE=[0] python -m training.run.generate_raw_audio_dataset -i <~/path/to/common-voice> --positive-pct 100 --negative-pct 5

This script generate a dataset for fire under datasets directory. fire dataset has two directories, one for positive samples and one for negative samples. Each contains audio files, transcriptions, and json files for training, dev, test set

datasets/
└── fire
    ├── negative
    │   └── audio
    └── positive
        ├── audio
        ├── metadata-dev.jsonl
        ├── metadata-test.jsonl
        └── metadata-training.jsonl

Before the alignment each entry in metadata-*.jsonl only has relative path to the audio file and the transcription

{"path": "common_voice_en_19633015.wav", "phone_strings": null, "words": null, "phone_end_timestamps": null, "end_timestamps": null, "transcription": "During World War One, Sasha Chorny served as a private at a field hospital."}
{"path": "common_voice_en_19980734.wav", "phone_strings": null, "words": null, "phone_end_timestamps": null, "end_timestamps": null, "transcription": "\"Laura's world has been jolted.\""}
{"path": "common_voice_en_18651632.wav", "phone_strings": null, "words": null, "phone_end_timestamps": null, "end_timestamps": null, "transcription": "If we look after the world and each other."}
...
  1. Next step is to align orthographic transcriptions to the audio using MFA. We only need to process positive samples as we don't need the alignment for the negative samples
mkdir -p datasets/fire/positive/alignment
pushd montreal-forced-aligner
./bin/mfa_align --num_jobs 12 ../datasets/fire/positive/audio librispeech-lexicon.txt pretrained_models/english.zip ../datasets/fire/positive/alignment
popd

The alignment can be found under datasets/fire/positive/alignment directory

positive/
└── alignment
    ├── oovs_found.txt
    ├── utterance_oovs.txt
    └── audio
        ├── common_voice_en_22465933.TextGrid
        ├── common_voice_en_20995965.TextGrid
        ...
        └── common_voice_en_92432.TextGrid

The alignment file (.TextGrid) looks like the following

...
intervals [2]:
	xmin = 0.750
	xmax = 0.930
	text = "it"
intervals [3]:
	xmin = 0.930
	xmax = 1.590
	text = "closed"
intervals [4]:
	xmin = 1.590
	xmax = 2.270
	text = "down"
...
  1. Use MFA to generate alignment for the positive set:
mfa_align datasets/fire/positive/audio eng.dict pretrained_models/english.zip datasets/fire/positive/alignment

If this process is raising an error, you can take a look at ~/Documents/MFA/audio/train/mfcc/log/make_mfcc.0.log

It's often due to missing openblas or fortran packages

If openblas is installed and the error message is coming from missing raw_mfcc.0.scp file, you can take a look at this issue

  1. Attach MFA alignments to the positive datasets:
python -m training.run.attach_alignment \
  --input-raw-audio-dataset datasets/fire/positive \
  --token-type word \
  --alignment-type mfa \
  --alignments-path datasets/fire/positive/alignment
  1. Generate some mock alignment for the negative set, where we don't care about alignment:
python -m training.run.attach_alignment \
  --input-raw-audio-dataset datasets/fire/negative \
  --token-type word \
  --alignment-type stub
  1. (Optional) Stitch vocab samples of aligned dataset to generate wakeword samples
VOCAB='["fire"]' INFERENCE_SEQUENCE=[0] python -m training.run.stitch_vocab_samples --dataset-path "datasets/fire/positive"