This is a transformation block that uses audiomentations library to mix audio files with noise files to a specific SNR.
The block adds noise to all files from the audio directory. For each audio file, some random noise file is selected and mixed with to an SNR target between min and max values (uniform distribution). For a fixed SNR, use the same value for min and max.
Each new generated sample is applied a label based on the labelling method and extra metadata is also added (generation date, SNR values, original audio and noise files).
- Path to noise files: Bucket path/prefix with noise files (ie: /mnt/s3fs/noise_dir/)
- Path to audio/clean files: Bucket path/prefix with audio files (ie: /mnt/s3fs/audio_dir/)
- Min SNR: min SNR value (ie 3.0)
- Max SNR: max SNR value (ie 5.0)
- Labelling method: 'auto' or 'manual'. If 'auto' is selected, label is extracted from the filename such as <label>.<rest-of-filename>.wav
- Label: will be used only for 'manual' labelling method
- Upload to category: how to split generated samples between training and test sets
You can modify this repository or just push it as a new custom Synthetic Data transformation block.
- Install the Edge Impulse CLI.
- Open a command prompt or terminal, and navigate to this folder.
- Create a new transformation block:
$ edge-impulse-blocks init
In which organization do you want to create this block? Aurelien Demo Org
Attaching block to organization 'Aurelien Demo Org'
- Push the block:
$ edge-impulse-blocks push
-
Mount bucket to your Synthetic Data block:
- Go to your Edge Impulse organization.
- Head to the "Synthetic Data" Blocks area under "Custom Blocks" and edit your uploaded block
- Click the + icon next to "Additional Mount Points" and choose "Bucket". Set the mounting location as /mnt/s3fs/
- Save the block.
-
You can now access your modified block from Data acquisition > Synthetic data on any enterprise project.
First, copy noise and audio files to input/ subdirectories.
-
Install the dependencies:
pip3 install -r requirements.txt
-
Run the generate script:
python3 transform.py --noise-dir input/noise_dir --audio-dir input/audio_dir --min-snr 3.0 --max-snr 5.0 --skip-upload --labelling-method auto
-
Generated files will be written to the output folder.
- Build the docker container
docker build -t mix-audio-block .
- Run the container and provide your Edge Impulse Project API Key:
docker run --rm -it -v $PWD:/app -e EI_PROJECT_API_KEY='YOUR_API_KEY' mix-audio-block --noise-dir input/noise_dir --audio-dir input/audio_dir --min-snr 3.0 --max-snr 5.0 --labelling-method auto
- Generated files will be sent to your Edge Impulse project, including metadata.
If you want to build your own custom Synthetic Data block, you'll need to parse the (optional) --synthetic-data-job-id
argument. When uploading data to the ingestion service you need to then pass the value from this argument to the x-synthetic-data-job-id
header. transform.py implements this. This is required so we know which job generated what data, and is used to render the UI on the Synthetic Data page.