<!--
{
  "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/DataSource/labeledDirectories(at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML17MLSoundClassifierV10DataSourceO18labeledDirectoriesyAE10Foundation3URLV_tcAEmF"
  },
  "title" : "MLSoundClassifier.DataSource.labeledDirectories(at:)"
}
-->

# MLSoundClassifier.DataSource.labeledDirectories(at:)

Creates a data source from a folder with subfolders that each contain audio files.

```
case labeledDirectories(at: URL)
```

## Parameters

`at`

URL : The URL to a folder in the file system that contains folders of audio files. The data source
uses the name of each folder as the classification label for the audio content it contains.

## Discussion

This data source uses each subdirectory’s name as the label for the audio files contained within them. For
example, for a directory that contains a `Laughter` subdirectory, the data source applies the label
`"Laughter"` to each audio file in that subdirectory.

```swift
// Build a URL to the directory that contains the labeled directories.
let home = FileManager.default.homeDirectoryForCurrentUser
let documents = home.appendingPathComponent("Documents")
let labeledDirectories = documents.appendingPathComponent("Labeled Audio Directories")

// Labeled Audio Directories/
// ├── Laughter/
// │ ├── Laughter1.m4a
// │ ├── 20190229164259.m4a
// │ ├── .
// │ ├── .
// │ ├── .
// │ └── AudienceLaughing.mp3
// └── Applause
//   ├── misc-clapping.mp3
//   ├── 20190229164211.m4a
//   ├── .
//   ├── .
//   ├── .
//   └── AudienceClapping.m4a

// Create a data source from the labeled directories.
let soundDataSource = MLSoundClassifier.DataSource.labeledDirectories(at: labeledDirectories)

// Train a sound classifier with the data source.
let soundClassifier = try MLSoundClassifier(trainingData: soundDataSource)
```

---

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)