<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLSoundClassifier/DataSource/filesByLabel(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLSoundClassifierV10DataSourceO12filesByLabelyAESDySSSay10Foundation3URLVGGcAEmF"
  },
  "title" : "MLSoundClassifier.DataSource.filesByLabel(_:)"
}
-->

# MLSoundClassifier.DataSource.filesByLabel(_:)

Creates a data source from a dictionary.

```
case filesByLabel([String : [URL]])
```

## Parameters

`dictionary`

A dictionary that contains a collection of labeled audio files. Each of the dictionary’s
keys is a label, and each key’s value is an array of audio-file URLs.

## Discussion

This data source uses each key in the dictionary to label the audio files in its associated URL array. The
following code demonstrates how to create a dictionary with two labels, `"Laughter"` and `"Applause"`.

```swift
// Get the Documents directory URL.
guard let documentsURL = FileManager.default.urls(for: .documentDirectory,
                                                  in: .userDomainMask).first else {
    fatalError("Can't find Documents directory.")
}

// Build a URL to the ~/Documents/Sounds directory, which contains the training data.
let url = documentsURL.appendingPathComponent("Sounds")

// Create a dictionary of arrays of audio file URLs keyed by a label.
let trainingData = [
    "Laughter": [
        url.appendingPathComponent("Laughter.1.aif"),
        url.appendingPathComponent("Laughter.2.wav")
    ],
    "Applause": [
        url.appendingPathComponent("Applause.1.mp3"),
        url.appendingPathComponent("Applause.2.caf")
    ]
]

let soundClassifier = try MLSoundClassifier(trainingData: trainingData)
```

The value for each label key is an array of URLs to audio files of laughter and applause, respectively.

> Note: Use a minimum of 10 sound files per label to train a sound classifier.

---

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)