---
title: "MLSoundClassifier.DataSource.filesByLabel(_:)"
framework: createml
role: symbol
role_heading: Case
path: "createml/mlsoundclassifier/datasource/filesbylabel(_:)"
---

# MLSoundClassifier.DataSource.filesByLabel(_:)

Creates a data source from a dictionary.

## Declaration

```swift
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

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". // 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.

## See Also

### Creating a data source

- [MLSoundClassifier.DataSource.labeledDirectories(at:)](createml/mlsoundclassifier/datasource/labeleddirectories(at:).md)
- [MLSoundClassifier.DataSource.labeledFiles(at:)](createml/mlsoundclassifier/datasource/labeledfiles(at:).md)
- [MLSoundClassifier.DataSource.features(table:featureColumn:labelColumn:parameters:)](createml/mlsoundclassifier/datasource/features(table:featurecolumn:labelcolumn:parameters:).md)
- [MLSoundClassifier.DataSource.featuresDataFrame(_:featureColumn:labelColumn:parameters:)](createml/mlsoundclassifier/datasource/featuresdataframe(_:featurecolumn:labelcolumn:parameters:).md)
- [MLSoundClassifier.FeatureExtractionParameters](createml/mlsoundclassifier/featureextractionparameters.md)
