|
| 1 | + # Google Speech Commands 12-Class Dataset |
| 2 | + |
| 3 | + A TensorLab-compatible 12-class variant of the Google Speech Commands dataset for keyword spotting and audio classification experiments using TinyML models such as DSCNN. |
| 4 | + --- |
| 5 | + |
| 6 | + ## Dataset Source |
| 7 | + |
| 8 | + Downloaded automatically via TorchAudio: |
| 9 | + |
| 10 | + ```python |
| 11 | + torchaudio.datasets.SPEECHCOMMANDS( |
| 12 | + root=root, |
| 13 | + url="speech_commands_v0.02", |
| 14 | + folder_in_archive="SpeechCommands", |
| 15 | + download=True, |
| 16 | + ) |
| 17 | + ``` |
| 18 | + ## Classes |
| 19 | + |
| 20 | +``` |
| 21 | + ┌────────────────┬──────────────────────────────────────────────────────────┐ |
| 22 | + │ Type │ Labels │ |
| 23 | + ├────────────────┼──────────────────────────────────────────────────────────┤ |
| 24 | + │ Known keywords │ down, go, left, no, off, on, right, stop, up, yes │ |
| 25 | + ├────────────────┼──────────────────────────────────────────────────────────┤ |
| 26 | + │ Unknown │ _unknown_ - all non-keyword words (e.g. bird, cat, tree) │ |
| 27 | + ├────────────────┼──────────────────────────────────────────────────────────┤ |
| 28 | + │ Silence │ _silence_ - 1-second clips from _background_noise_/ │ |
| 29 | + └────────────────┴──────────────────────────────────────────────────────────┘ |
| 30 | +``` |
| 31 | + |
| 32 | + ## Quick Start |
| 33 | + |
| 34 | + - Install dependencies |
| 35 | + |
| 36 | + ```python |
| 37 | + python -m pip install torch torchaudio scipy pydub numpy tqdm |
| 38 | +``` |
| 39 | + |
| 40 | + - Generate the dataset |
| 41 | + |
| 42 | + ```python |
| 43 | + python generate_dataset.py |
| 44 | + ``` |
| 45 | + |
| 46 | + ## Output Structure |
| 47 | + |
| 48 | +``` |
| 49 | + SpeechCommands/ |
| 50 | + ├── speech_commands_v0.02/ # Original downloaded dataset |
| 51 | + │ ├── down/ |
| 52 | + │ ├── go/ |
| 53 | + │ └── _background_noise_/ |
| 54 | + └── classes/ # TensorLab-ready dataset |
| 55 | + ├── down/ |
| 56 | + ├── go/ |
| 57 | + ├── left/ |
| 58 | + ├── no/ |
| 59 | + ├── off/ |
| 60 | + ├── on/ |
| 61 | + ├── right/ |
| 62 | + ├── stop/ |
| 63 | + ├── up/ |
| 64 | + ├── yes/ |
| 65 | + ├── _silence_/ |
| 66 | + └── _unknown_/ |
| 67 | +``` |
| 68 | + |
| 69 | + What generate_dataset.py Does: |
| 70 | + |
| 71 | + 1. Downloads Google Speech Commands v0.02 via TorchAudio |
| 72 | + 2. Copies the 10 keyword classes into their own folders |
| 73 | + 3. Maps all other word classes into _unknown_ (prefixing the original label to avoid filename collisions) |
| 74 | + 4. Splits _background_noise_/ audio into 1-second clips for _silence_ |
| 75 | + 5. Saves everything under SpeechCommands/classes/ |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + ## How _silence_ Samples Are Generated |
| 80 | + Silence samples are not recorded speech - they are synthetic clips cut from the background noise audio files in_background_noise_/. |
| 81 | + **Source files:** all `.wav` files inside `SpeechCommands/speech_commands_v0.02/_background_noise_/` |
| 82 | + |
| 83 | + **Process (`create_silence_samples`):** |
| 84 | + |
| 85 | + 1. Each background noise file is loaded in full via `pydub.AudioSegment` |
| 86 | + 2. Raw PCM samples are extracted as a NumPy array |
| 87 | + 3. The array is sliced into 1-second windows using a sliding loop with 50% overlap. |
| 88 | + 4. Each segment is written to classes/_silence_/ as a 16-bit .wav file |
| 89 | + |
| 90 | + ## Recommended preset |
| 91 | + |
| 92 | +``` |
| 93 | + GoogleSpeechCommands_MFCC_Default = dict( |
| 94 | + data_processing_feature_extraction=dict( |
| 95 | + sampling_rate=16000, |
| 96 | + audio_duration_ms=1000, |
| 97 | + audio_feature="MFCC", |
| 98 | + n_mfcc=10, |
| 99 | + n_mels=40, |
| 100 | + frame_length_ms=30, |
| 101 | + frame_step_ms=20, |
| 102 | + normalize_audio=True, |
| 103 | + mono=True, |
| 104 | + variables=1, |
| 105 | + feat_ext_transform=["MFCC"], |
| 106 | + data_proc_transforms=[], |
| 107 | + ), |
| 108 | + common=dict( |
| 109 | + task_type=TASK_TYPE_AUDIO_CLASSIFICATION, |
| 110 | + ), |
| 111 | + ) |
| 112 | +``` |
| 113 | + |
| 114 | + |
| 115 | + ## MFCC Feature Extraction |
| 116 | + |
| 117 | + MFCCs (Mel Frequency Cepstral Coefficients) compactly represent the frequency characteristics of speech, making them |
| 118 | + well-suited for keyword spotting. |
| 119 | + |
| 120 | +``` |
| 121 | + ┌───────────────────┬──────────┐ |
| 122 | + │ Parameter │ Value │ |
| 123 | + ├───────────────────┼──────────┤ |
| 124 | + │ Sampling rate │ 16000 Hz │ |
| 125 | + ├───────────────────┼──────────┤ |
| 126 | + │ Audio duration │ 1000 ms │ |
| 127 | + ├───────────────────┼──────────┤ |
| 128 | + │ Frame length │ 30 ms │ |
| 129 | + ├───────────────────┼──────────┤ |
| 130 | + │ Frame step │ 20 ms │ |
| 131 | + ├───────────────────┼──────────┤ |
| 132 | + │ MFCC coefficients │ 10 │ |
| 133 | + ├───────────────────┼──────────┤ |
| 134 | + │ Mel bins │ 40 │ |
| 135 | + └───────────────────┴──────────┘ |
| 136 | +``` |
| 137 | + Output feature shape: [N, 1, 49, 10] |
| 138 | + (batch size × 1 channel × 49 time frames × 10 MFCC coefficients) |
| 139 | + |
| 140 | + |
| 141 | + ## DSCNN Model |
| 142 | + |
| 143 | + The recommended model is DSCNN (Depthwise Separable Convolutional Neural Network), designed for efficient TinyML |
| 144 | + inference on our NPU |
| 145 | + |
| 146 | + Architecture |
| 147 | + |
| 148 | + Conv10x4 / stride 2 |
| 149 | + Dropout |
| 150 | + Depthwise3x3 + Pointwise1x1 ×4 |
| 151 | + Dropout |
| 152 | + AdaptiveAvgPool |
| 153 | + Fully Connected (→ 12 classes) |
| 154 | + |
| 155 | + Filters: 64 | Output classes: 12 |
| 156 | + |
| 157 | + ### Why DSCNN |
| 158 | + |
| 159 | + A standard convolution performs spatial filtering and channel mixing in one operation. DSCNN splits this into: |
| 160 | + |
| 161 | + - Depthwise conv - spatial filtering independently per channel |
| 162 | + - Pointwise conv - 1×1 convolution for channel mixing |
| 163 | + |
| 164 | + This reduces computation and model size while maintaining strong keyword spotting accuracy, making it suitable for |
| 165 | + embedded deployment. |
| 166 | + |
0 commit comments