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
creates a datastore ads
= audiodatastore(location
)ads
based on an audio file or collection of audio
files in location
.
specifies additional properties using one or more name-value pair arguments.ads
= audiodatastore(location
,name,value
)
input arguments
location
— files or folders to include in datastore
fileset
object | path | dsfileset
object
files or folders included in the datastore, specified as a
fileset
object, as file paths, or as a dsfileset
object.
fileset
object — you can specifylocation
as afileset
object. specifying the location as afileset
object leads to a faster construction time for datastores compared to specifying a path ordsfileset
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 adsfileset
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:///
. for more information, see work with remote data.path_to_file
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
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')
includesubfolders
— subfolder inclusion flag
false
(default) | true
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
labelsource
— source providing label data
'none'
(default) | 'foldernames'
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
fileextensions
— audio file extensions
character vector | cell array of character vectors | string scalar | string array
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
— files included in datastore
character vector | cell array of character vectors | string scalar | string array
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
folders
— folders used to create audio datastore
n-by-1 cell array of character vectors
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
labels
— file labels
categorical, logical, or numeric vector | cell array | string array | table
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
outputdatatype
— data type of output read
'double'
(default) | 'native'
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 whenoutputdatatype
is set to native.
the default value of this property is 'double'
.
data types: char
| string
alternatefilesystemroots
— alternate file system root paths
string row vector | cell array of string vectors | cell array of character vectors
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
supportedoutputformats
— formats supported for writing audio files
["wav","flac","ogg","opus","mp4","m4a"]
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
defaultoutputformat
— default output audio file format
"wav"
(default)
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
create audio datastore
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 file extensions to include
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 r2018br2022b: support for opus audio file format
the audiodatastore
object supports reading and writing opus file format
(.opus
).
see also
| |
topics
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)