The MediaPipe Audio Classifier task lets you classify audio clips into a set of defined categories, such as guitar music, a train whistle, or a bird's song. The categories are defined during the training of the model. This task operates on audio data with a machine learning (ML) model as independent audio clips or a continuous stream and outputs a list of potential categories ranked by descending probability score.
Start using this task by following one of these implementation guides for your target platform. These platform-specific guides walk you through a basic implementation of this task, including a recommended model, and code example with recommended configuration options:
- Android - Code example - Guide
- Python - Code example - Guide
- Web - Code example - Guide
These platform-specific guides walk you through a basic implementation of this task, including a recommended model, and code example with recommended configuration options.
This section describes the capabilities, inputs, outputs, and configuration options of this task.
- Input audio processing - Processing includes audio resampling, buffering, framing, and fourier transform.
- Label map locale - Set the language used for display names
- Score threshold - Filter results based on prediction scores.
- Top-k detection - Filter the number detection results.
- Label allowlist and denylist - Specify the categories detected.
|Task inputs||Task outputs|
|Input can be one of the following data types:
||Audio Classifier outputs a list of categories containing:
This task has the following configuration options:
|Option Name||Description||Value Range||Default Value|
||Sets the running mode for the task. Audio Classifier has two modes:
AUDIO_CLIPS: The mode for running the audio task on independent audio clips.
AUDIO_STREAM: The mode for running the audio task on an audio stream, such as from microphone. In this mode, resultListener must be called to set up a listener to receive the classification results asynchronously.
||Sets the language of labels to use for display names provided in the
metadata of the task's model, if available. Default is ||Locale code||en|
||Sets the optional maximum number of top-scored classification results to return. If < 0, all available results will be returned.||Any positive numbers||
||Sets the prediction score threshold that overrides the one provided in the model metadata (if any). Results below this value are rejected.||[0.0, 1.0]||Not set|
||Sets the optional list of allowed category names. If non-empty,
classification results whose category name is not in this set will be
filtered out. Duplicate or unknown category names are ignored.
This option is mutually exclusive with
||Any strings||Not set|
||Sets the optional list of category names that are not allowed. If
non-empty, classification results whose category name is in this set will be filtered
out. Duplicate or unknown category names are ignored. This option is mutually
||Any strings||Not set|
||Sets the result listener to receive the classification results
asynchronously when the Audio Classifier is in the audio stream
mode. Can only be used when running mode is set to
The Audio Classifier requires an audio classification model to be downloaded and stored in your project directory. Start with the default, recommended model for your target platform when you start developing with this task. The other available models typically make trade-offs between performance, accuracy, resolution, and resource requirements, and in some cases, include additional features.
Yamnet model (recommended)
The Yamnet model is an audio event classifier trained on the AudioSet dataset to predict audio events defined in the AudioSet data. For information on the audio events recognized by this model, see the model labels list.