This is an Edge Impulse AI Actions block that uses Audio Spectrogram Transformers from HuggingFace to automatically label audio data. You can use this repo as the basis for custom tasks that use big ML models to help with labeling or data quality tasks in your project.
If you just want to use this block as a labeling tool in your Edge Impulse project you don't need this repo. Just go to any project, select Data acquisition > AI Actions, choose Audio labeling with Audio Spectrogram Transformers (available for professional and enterprise projects only).
You can use this repository as a basis to integrate any model that's deployed using HuggingFace's Serverless Inference API. The model we're using here is MIT/ast-finetuned-audioset-10-10-0.4593, but it should be easy to adapt this repository to any other model. If your desired HuggingFace model is not available through HuggingFace's APIs, see zero-shot-object-detector-labeling-block for information on how to deploy models using Beam.cloud.
- 
Create a new Edge Impulse project, and add some unlabeled audio, e.g. with some speech. Unlabeled audio data with some speech and some music 
- 
Create a file called ids.jsonand add the IDs of the samples you want to label. You can find the sample ID by clicking the 'expand' button on Data acquisiton.Add these IDs to the ids.jsonfile as an array of numbers, e.g.:[1299267659, 1299267609, 1299267606] 
- 
Load your Edge Impulse API key, and your HuggingFace API Key: export EI_PROJECT_API_KEY=ei_44... export HF_API_KEY=hf_ng...You can find your Edge Impulse API Key via Dashboard > Keys. You can find your HuggingFace API Key via Access tokens in your HuggingFace profile. 
- 
Install the Python dependencies: python3 -m venv .venv source .venv/bin/activate pip3 install -r requirements.txt
- 
Run transform.pyto label your data:python3 -u transform.py \ --audioset-labels "speech, music" \ --win-size-ms 1000 \ --win-stride-ms 1000 \ --min-confidence 0.2 \ --data-ids-file ids.jsonValid labels: Here's the full list of valid labels: AudioSet dataset 
- 
Afterwards you'll have labeled data in your project! 
If you've modified this block, you can push it back to Edge Impulse so it's available to everyone in your organization.
- 
Update parameters.jsonto update the name and description of your block.
- 
Initialize and push the block: $ edge-impulse-blocks init $ edge-impulse-blocks push
- 
Afterwards, you can run your block through Data acquisition > AI Actions in any Edge Impulse project. 
AI Actions blocks should be able to run in 'preview' mode (triggered when you click Label preview data in the Studio) - where changes are staged but not directly applied. If this is the case --propose-actions <job-id> is passed into your block. When you see this flag you should not apply changes directly (e.g. via raw_data_api.set_sample_structured_labels) but rather use the raw_data_api.set_sample_proposed_changes API. Search for this API in transform.py to see how this should be used.


