main content

datastore for collection of audio files -凯发k8网页登录

datastore for collection of audio files

since r2018b

description

use an audiodatastore object to manage a collection of audio files, where each individual audio file fits in memory, but the entire collection of audio files does not necessarily fit.

creation

description

example

ads = audiodatastore(location) creates a datastore ads based on an audio file or collection of audio files in location.

example

ads = audiodatastore(location,name,value) specifies additional properties using one or more name-value pair arguments.

input arguments

files or folders included in the datastore, specified as a fileset object, as file paths, or as a dsfileset object.

  • fileset object — you can specify location as a fileset object. specifying the location as a fileset object leads to a faster construction time for datastores compared to specifying a path or dsfileset object. for more information, see .

  • file path — you can specify a single file path as a character vector or string scalar. you can specify multiple file paths as a cell array of character vectors or a string array.

  • dsfileset object — you can specify a dsfileset object. for more information, see .

files or folders may be local or remote:

  • local files or folders — specify local paths to files or folders. if the files are not in the current folder, then specify full or relative paths. files within subfolders of the specified folder are not automatically included in the datastore. you can use the wildcard character (*) when specifying the local path. this character specifies that the datastore include all matching files or all files in the matching folders.

  • remote files or folders — specify full paths to remote files or folders as a uniform resource locator (url) of the form hdfs:///path_to_file. for more information, see work with remote data.

when you specify a folder, the datastore includes only files with supported file formats and ignores files with any other format. to specify a custom list of file extensions to include in your datastore, see the fileextensions property.

example: 'song.wav'

example: '../dir/music/song.wav'

example: {'c:\dir\music\song.wav','c:\dir\speech\english.mp3'}

example: 'c:\dir\music\*.ogg'

data types: char | string | cell

name-value arguments

specify optional pairs of arguments as name1=value1,...,namen=valuen, where name is the argument name and value is the corresponding value. name-value arguments must appear after other arguments, but the order of the pairs does not matter.

before r2021a, use commas to separate each name and value, and enclose name in quotes.

example: ads = audiodatastore('c:\dir\audiodata','fileextensions','.ogg')

subfolder inclusion flag, specified as the comma-separated pair consisting of 'includesubfolders' and true or false. specify true to include all files and subfolders within each folder or false to include only the files within each folder.

if you do not specify 'includesubfolders', then the default value is false.

example: 'includesubfolders',true

data types: logical | double

source providing label data, specified as the comma-separated pair consisting of 'labelsource' and 'none' or 'foldernames'. if 'none' is specified, then the labels property is empty. if 'foldernames' is specified, then labels are assigned according to the folder names and stored in the labels property. you can later modify the labels by accessing the labels property directly.

data types: char | string

audio file extensions, specified as the comma-separated pair consisting of 'fileextensions' and a character vector, cell array of character vectors, string scalar, or string array. if you do not specify 'fileextensions', then audiodatastore automatically includes all supported file types:

  • .wav

  • .avi

  • .aif

  • .aifc

  • .aiff

  • .mp3

  • .au

  • .snd

  • .mp4

  • .m4a

  • .flac

  • .ogg

  • .mov

  • .opus

example: 'fileextensions','.wav'

example: 'fileextensions',{'.mp3','.mp4'}

data types: char | cell | string

in addition to these name-value pairs, you also can specify any of the properties on this page as name-value pairs, except for the files property.

properties

files included in the datastore, specified as a character vector, cell array of character vectors, string scalar, or string array. each character vector or string is a full path to a file. the location argument in the audiodatastore defines files when the datastore is created.

data types: char | cell | string

this property is read-only.

folders used to create the audio datastore, returned as an n-by-1 cell array of character vectors. each row specifies a unique folder containing audio files that the audiodatastore object points to.

data types: cell

file labels for the files in the datastore, specified as a vector, a cell array, a string array, or a table. the order of the labels in the array or table corresponds to the order of the associated files in the datastore.

if you specify labelsource as 'foldernames' when creating the audiodatastore object, then the label name for a file is the name of the folder containing it. if you do not specify labelsource as 'foldernames', then labels is an empty cell array or string array. if you change the files property after the datastore is created, then the labels property is not automatically updated to incorporate the added fields.

data types: categorical | cell | logical | double | single | string | table

data type of the output, specified as 'double' or 'native'.

  • 'double' –– double-precision normalized samples.

  • 'native' –– native data type found in the file. refer to for more information about data types when outputdatatype is set to native.

the default value of this property is 'double'.

data types: char | string

alternate file system root paths, specified as a string row vector, a cell array of string vectors, or a cell array of character vectors. use alternatefilesystemroots when you create a datastore on a local machine but must access and process data on another machine (possibly of a different operating system). also, when processing data using parallel computing toolbox™ and matlab® parallel server™, and the data is stored on your local machines with a copy of the data available on different platform cloud or cluster machines, you must use alternatefilesystemroots to associate the root paths.

  • to associate a set of root paths that are equivalent to one another, specify alternatefilesystemroots as a string vector. for example:

    ["z:\datasets","/mynetwork/datasets"]
  • to associate multiple sets of root paths that are equivalent for the datastore, specify alternatefilesystemroots as a cell array containing multiple rows, where each row represents a set of equivalent root paths. specify each row in the cell array as either a string vector or a cell array of character vectors. for example:

    • specify alternatefilesystemroots as a cell array of string vectors.

      {["z:\datasets", "/mynetwork/datasets"]; ...
       ["y:\datasets", "/mynetwork2/datasets","s:\datasets"]}
    • alternatively, specify alternatefilesystemroots as a cell array of cell arrays of character vectors.

      {{'z:\datasets', '/mynetwork/datasets'}; ...
       {'y:\datasets", '/mynetwork2/datasets','s:\datasets'}}

the value of alternatefilesystemroots must satisfy these conditions:

  • contains one or more rows, where each row specifies a set of equivalent root paths.

  • each row specifies multiple root paths, and each root path must contain at least two characters.

  • root paths are unique and are not subfolders of one another.

  • contains at least one root path entry that points to the location of the files.

data types: char | cell | string

this property is read-only.

formats supported for writing audio files when using the function, specified as ["wav","flac","ogg","opus","mp4","m4a"].

data types: string

this property is read-only.

default output format for writing audio files when using the function, specified as "wav".

data types: string

object functions

read next consecutive audio file
read all audio files from datastore
reset datastore read pointer to start of data
return true if there is more data in datastore
shuffle files in datastore
create datastore with subset of files
read first file from datastore for preview
fraction of files read
splits datastore according to specified label proportions
count number of unique labels
partition datastore and return on partitioned portion
return estimate for reasonable number of partitions for parallel processing
combine data from multiple datastores
transform audio datastore
write datastore to files
determine whether datastore is partitionable
determine whether datastore is shuffleable

examples

specify the file path to the audio samples included with audio toolbox™.

folder = fullfile(matlabroot,'toolbox','audio','samples');

create an audio datastore that points to the specified folder.

ads = audiodatastore(folder)
ads = 
  audiodatastore with properties:
                       files: {
                              ' .../build/matlab/toolbox/audio/samples/ambiance-16-44p1-mono-12secs.wav';
                              ' .../matlab/toolbox/audio/samples/audioarray-16-16-4channels-20secs.wav';
                              ' .../toolbox/audio/samples/churchimpulseresponse-16-44p1-mono-5secs.wav'
                               ... and 33 more
                              }
                     folders: {
                              '/mathworks/devel/bat/bdoc23a/build/matlab/toolbox/audio/samples'
                              }
    alternatefilesystemroots: {}
              outputdatatype: 'double'
                      labels: {}
      supportedoutputformats: ["wav"    "flac"    "ogg"    "opus"    "mp4"    "m4a"]
         defaultoutputformat: "wav"

specify the file path to the audio samples included with audio toolbox™.

folder = fullfile(matlabroot,'toolbox','audio','samples');

create an audio datastore that points to the .ogg files in the specified folder.

ads = audiodatastore(folder,'fileextension','.ogg')
ads = 
  audiodatastore with properties:
                       files: {
                              ' .../build/matlab/toolbox/audio/samples/femalevolumeup-16-mono-11secs.ogg';
                              ' .../bat/bdoc23a/build/matlab/toolbox/audio/samples/hey-16-mono-6secs.ogg';
                              ' .../build/matlab/toolbox/audio/samples/malevolumeup-16-mono-6secs.ogg'
                               ... and 3 more
                              }
                     folders: {
                              '/mathworks/devel/bat/bdoc23a/build/matlab/toolbox/audio/samples'
                              }
    alternatefilesystemroots: {}
              outputdatatype: 'double'
                      labels: {}
      supportedoutputformats: ["wav"    "flac"    "ogg"    "opus"    "mp4"    "m4a"]
         defaultoutputformat: "wav"

version history

introduced in r2018b

see also

| |

topics

    网站地图