<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.15.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLSoundClassifier",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLSoundClassifierV"
  },
  "title" : "MLSoundClassifier"
}
-->

# MLSoundClassifier

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

```
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`](/documentation/CreateML/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

> Tip: Use single-channel audio files with a sample rate of 16 kHz or higher for best results.

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:

- [Creating an Image Classifier Model](/documentation/CreateML/creating-an-image-classifier-model)
- [Creating an Action Classifier Model](/documentation/CreateML/creating-an-action-classifier-model)

Add the sound classifier’s Core ML model to an Xcode project and use it to create an
<doc://com.apple.documentation/documentation/SoundAnalysis/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:

- <doc://com.apple.documentation/documentation/SoundAnalysis/classifying-sounds-in-an-audio-file>
- <doc://com.apple.documentation/documentation/SoundAnalysis/classifying-sounds-in-an-audio-stream>

## Topics

### Training a sound classifier asynchronously

[`train(trainingData:parameters:sessionParameters:)`](/documentation/CreateML/MLSoundClassifier/train(trainingData:parameters:sessionParameters:))

Begins an asynchronous sound classifier training session with a training dataset represented by a data source.

[`makeTrainingSession(trainingData:parameters:sessionParameters:)`](/documentation/CreateML/MLSoundClassifier/makeTrainingSession(trainingData:parameters:sessionParameters:))

Creates an asynchronous training session for a sound classifier.

[`resume(_:)`](/documentation/CreateML/MLSoundClassifier/resume(_:))

Begins or continues an asynchronous training session for a sound classifier.

[`restoreTrainingSession(sessionParameters:)`](/documentation/CreateML/MLSoundClassifier/restoreTrainingSession(sessionParameters:))

Creates an asynchronous training session for a sound classifier by restoring an existing training session’s
state from its parameters.

[`extractFeatures(trainingData:parameters:sessionParameters:)`](/documentation/CreateML/MLSoundClassifier/extractFeatures(trainingData:parameters:sessionParameters:))

Begins an asynchronous session that extracts sound features from a data source of sound files.

[`MLSoundClassifier.FeatureExtractionParameters`](/documentation/CreateML/MLSoundClassifier/FeatureExtractionParameters)

Parameters that affect the process of extracting sound features from audio files.

### Creating a sound classifier from a checkpoint

[`init(checkpoint:)`](/documentation/CreateML/MLSoundClassifier/init(checkpoint:))

Creates a sound classifier from a training session checkpoint.

### Training a sound classifier synchronously

[`init(trainingData:parameters:)`](/documentation/CreateML/MLSoundClassifier/init(trainingData:parameters:))

Creates a sound classifier with a training dataset represented by a data source.

### Evaluating a sound classifier

[`evaluation(on:)`](/documentation/CreateML/MLSoundClassifier/evaluation(on:))

Generates metrics by evaluating the sound classifier’s performance on a dataset represented by a data source.

[`trainingMetrics`](/documentation/CreateML/MLSoundClassifier/trainingMetrics)

Measurements of the classifier’s performance on the training data set.

[`validationMetrics`](/documentation/CreateML/MLSoundClassifier/validationMetrics)

Measurements of the image classifier’s performance on the validation dataset.

### Testing a sound classifier

[`predictions(from:)`](/documentation/CreateML/MLSoundClassifier/predictions(from:))

Generates predictions for an array of audio files.

[`predictions(from:overlapFactor:predictionTimeWindowSize:)`](/documentation/CreateML/MLSoundClassifier/predictions(from:overlapFactor:predictionTimeWindowSize:))

Generates predictions that use an overlap factor and time window size for an array of audio files.

### Saving a sound classifier

[`write(to:metadata:)`](/documentation/CreateML/MLSoundClassifier/write(to:metadata:))

Exports the sound classifier as a model file to a location in the file system.

[`write(toFile:metadata:)`](/documentation/CreateML/MLSoundClassifier/write(toFile:metadata:))

Exports the sound classifier as a model file to a path in the file system.

### Inspecting a sound classifier model

[`model`](/documentation/CreateML/MLSoundClassifier/model)

The underlying model instance of the sound classifier stored in memory.

[`modelParameters`](/documentation/CreateML/MLSoundClassifier/modelParameters-swift.property)

The model configuration parameters the sound classifier used during its training session.

### Describing a sound classifier

[`description`](/documentation/CreateML/MLSoundClassifier/description)

A text representation of the sound classifier.

[`debugDescription`](/documentation/CreateML/MLSoundClassifier/debugDescription)

A text representation of the sound classifier that’s suitable for output during debugging.

[`playgroundDescription`](/documentation/CreateML/MLSoundClassifier/playgroundDescription)

A description of the sound classifier in a playground.

### Supporting types

[`MLSoundClassifier.DataSource`](/documentation/CreateML/MLSoundClassifier/DataSource)

A representation of a sound-classifier dataset located in the file system or in a data table.

[`MLSoundClassifier.ModelParameters`](/documentation/CreateML/MLSoundClassifier/ModelParameters-swift.struct)

Parameters that affect the process of training a sound-classifier model.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)