Extract Audio Features

Streamline audio feature extraction in the Live Editor

Description

The Extract Audio Features task enables you to configure an optimized feature extraction pipeline by selecting features and parameters graphically. You can reuse the output from Extract Audio Features to apply feature extraction to entire data sets. The task automatically generates MATLAB® code for your live script.

Using this task, you can:

  • Extract features of audio signals common to machine learning and deep learning workflows.

  • Create a feature extraction object for use with large data sets.

To learn more about interactive tasks in live scripts, see Add Interactive Tasks to a Live Script (MATLAB).

Open the Task

  • On the Live Editor tab, select Task > Extract Audio Features.

  • In a code block in the script, type a relevant keyword, such as extract, audio, or feature. Select Extract Audio Features from the suggested command completions.

Examples

expand all

Read in an audio signal, audioIn, and its sample rate, fs.

[audioIn,fs] = audioread('FemaleSpeech-16-8-mono-3secs.wav');

Extract features from the audio signal using the Extract Audio Features task. Set the input audio data to audioIn and the sample rate to fs. Select the spectral crest, flux, slope, entropy, and rolloff point to extract.

Create an audioDatastore object that points to audio samples included with Audio Toolbox™.

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

Find all files that correspond to a sample rate of 44.1 kHz and then subset the datastore.

keepFile = cellfun(@(x)contains(x,'44p1'),ads.Files);
ads = subset(ads,keepFile);

Read one file from the data set.

[audioIn,adsInfo] = read(ads);
fs = adsInfo.SampleRate;

Extract audio features from audioIn using the Extract Audio Features live task.

The Extract Audio Features live task returns an array containing the extracted features. The dimensions of the array are numHops by numFeatures by numChannels, where numHops is the number of windows analyzed, numFeatures is the number of features you extracted, and numChannels is the number of channels in the original audio.

[numHops,numFeatures,numChannels] = size(features)
numHops =

        1053


numFeatures =

    43


numChannels =

     1

You can use the output column mapping to determine which columns of features correspond to which features you requested.

plot(features(:,40,:))
title('Spectral Centroid')
xlabel('Hop')
ylabel('Frequency (Hz)')

The Extract Audio Features task also returns a configured audioFeatureExtractor object. The object is configured by the parameters you set in the task.

extractor
extractor = 

  audioFeatureExtractor with properties:

   Properties
                     Window: [1024×1 double]
              OverlapLength: 512
                 SampleRate: 44100
                  FFTLength: []
    SpectralDescriptorInput: 'linearSpectrum'

   Enabled Features
     gtcc, gtccDelta, gtccDeltaDelta, spectralCentroid, spectralEntropy, pitch
     harmonicRatio

   Disabled Features
     linearSpectrum, melSpectrum, barkSpectrum, erbSpectrum, mfcc, mfccDelta
     mfccDeltaDelta, spectralCrest, spectralDecrease, spectralFlatness, spectralFlux, spectralKurtosis
     spectralRolloffPoint, spectralSkewness, spectralSlope, spectralSpread


   To extract a feature, set the corresponding property to true.
   For example, obj.mfcc = true, adds mfcc to the list of enabled features.

You can use the configured audioFeatureExtractor object to extract features from the entire data set. For example, while the audioDatastore object has unread data, read a file from the datastore and then extract the features. First, reset the audioDatastore object so that you read from the beginning.

reset(ads)
while hasdata(ads)
    audioIn = read(ads);
    features = extract(extractor,audioIn);
end

Copyright 2019 The MathWorks, Inc.

Tips

The Extract Audio Features task provides a graphical user interface to configure an audioFeatureExtractor object. For details on the configuration parameters, see audioFeatureExtractor.

Introduced in R2020a