---
title: MLSoundClassifier
framework: createml
role: symbol
role_heading: Structure
path: createml/mlsoundclassifier
---

# MLSoundClassifier

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

## Declaration

```swift
struct MLSoundClassifier
```

## Overview

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 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 Creating an Action Classifier Model 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: Classifying Sounds in an Audio File Classifying Sounds in an Audio Stream

## Topics

### Training a sound classifier asynchronously

- [train(trainingData:parameters:sessionParameters:)](createml/mlsoundclassifier/train(trainingdata:parameters:sessionparameters:).md)
- [makeTrainingSession(trainingData:parameters:sessionParameters:)](createml/mlsoundclassifier/maketrainingsession(trainingdata:parameters:sessionparameters:).md)
- [resume(_:)](createml/mlsoundclassifier/resume(_:).md)
- [restoreTrainingSession(sessionParameters:)](createml/mlsoundclassifier/restoretrainingsession(sessionparameters:).md)
- [extractFeatures(trainingData:parameters:sessionParameters:)](createml/mlsoundclassifier/extractfeatures(trainingdata:parameters:sessionparameters:).md)
- [MLSoundClassifier.FeatureExtractionParameters](createml/mlsoundclassifier/featureextractionparameters.md)

### Creating a sound classifier from a checkpoint

- [init(checkpoint:)](createml/mlsoundclassifier/init(checkpoint:).md)

### Training a sound classifier synchronously

- [init(trainingData:parameters:)](createml/mlsoundclassifier/init(trainingdata:parameters:).md)

### Evaluating a sound classifier

- [evaluation(on:)](createml/mlsoundclassifier/evaluation(on:).md)
- [trainingMetrics](createml/mlsoundclassifier/trainingmetrics.md)
- [validationMetrics](createml/mlsoundclassifier/validationmetrics.md)

### Testing a sound classifier

- [predictions(from:)](createml/mlsoundclassifier/predictions(from:).md)
- [predictions(from:overlapFactor:predictionTimeWindowSize:)](createml/mlsoundclassifier/predictions(from:overlapfactor:predictiontimewindowsize:).md)

### Saving a sound classifier

- [write(to:metadata:)](createml/mlsoundclassifier/write(to:metadata:).md)
- [write(toFile:metadata:)](createml/mlsoundclassifier/write(tofile:metadata:).md)

### Inspecting a sound classifier model

- [model](createml/mlsoundclassifier/model.md)
- [modelParameters](createml/mlsoundclassifier/modelparameters-swift.property.md)

### Describing a sound classifier

- [description](createml/mlsoundclassifier/description.md)
- [debugDescription](createml/mlsoundclassifier/debugdescription.md)
- [playgroundDescription](createml/mlsoundclassifier/playgrounddescription.md)

### Supporting types

- [MLSoundClassifier.DataSource](createml/mlsoundclassifier/datasource.md)
- [MLSoundClassifier.ModelParameters](createml/mlsoundclassifier/modelparameters-swift.struct.md)

### Default Implementations

- [CustomDebugStringConvertible Implementations](createml/mlsoundclassifier/customdebugstringconvertible-implementations.md)
- [CustomPlaygroundDisplayConvertible Implementations](createml/mlsoundclassifier/customplaygrounddisplayconvertible-implementations.md)
- [CustomStringConvertible Implementations](createml/mlsoundclassifier/customstringconvertible-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomPlaygroundDisplayConvertible](swift/customplaygrounddisplayconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
