Contents

MLSoundClassifier

A machine learning model you train with audio files to recognize and identify sounds on a device.

Declaration

struct MLSoundClassifier

Overview

A sound classifier is a machine learning model that identifies and categorizes sounds in an app. Create a sound classifier by gathering a dataset of audio files and use them to train a model with MLSoundClassifier.

Assemble an audio dataset by recording or gathering audio files that best represent the sounds you want your app to identify. Additionally, create a negative class — a group of related noises the sound classifier might hear but aren’t relevant — by collecting or recording example sounds.

For example, say you’re creating a sound classifier to identify laughter and applause. In addition to gathering audio examples of people laughing and clapping, you can add an additional category for background noise. By adding recordings from various settings, such as theaters and amphitheaters, your sound classifier can distinguish the sounds of interest from environmental noises. In other words, the sound classifier won’t predict “Applause” when there isn’t any. Like any classifier, when you request a prediction, a sound classifier always returns one of the categories it learned from a training dataset.

Gather at least 10 audio examples of each sound category you want the sound classifier to learn, plus at least one negative class for background noise. The audio examples can be in any file format that Core Audio supports, including:

  • M4A

  • MP3

  • AIFF

  • WAV

Reduce a sound classifier’s bias — which can adversely affect its performance — by gathering audio files that use a consistent bit depth and sample rate.

Train, evaluate, and export your sound classifier by following similar steps to creating any other Create ML model type. For more information about the Create ML training workflow, see:

Add the sound classifier’s Core ML model to an Xcode project and use it to create an SNClassifySoundRequest at runtime. Your app uses the sound request to identify sounds in an audio file or audio stream by following the steps in the following articles, respectively:

Topics

Training a sound classifier asynchronously

Creating a sound classifier from a checkpoint

Training a sound classifier synchronously

Evaluating a sound classifier

Testing a sound classifier

Saving a sound classifier

Inspecting a sound classifier model

Describing a sound classifier

Supporting types

Default Implementations