%% Exclude Specific Sounds
% Read in an audio signal and call classifySound to inspect the most likely sounds arranged in chronological order of detection.

[audioIn,fs] = audioread("multipleSounds-16-16-mono-18secs.wav");
sounds = classifySound(audioIn,fs)

%
% Call classifySound again and set ExcludedSounds to Meow to exclude the sound Meow from the results. The segment previously classified as Meow is now classified as Cat, which is its immediate predecessor in the AudioSet ontology.

sounds = classifySound(audioIn,fs,"ExcludedSounds","Meow")

%
% Call classifySound again, and set ExcludedSounds to Cat. When you exclude a sound, all successors are also excluded. This means that excluding the sound Cat also excludes the sound Meow. The segment originally classified as Meow is now classified as Domestic animals, pets, which is the immediate predecessor to Cat in the AudioSet ontology.

sounds = classifySound(audioIn,fs,"ExcludedSounds","Cat")

%
% Call classifySound again and set ExcludedSounds to Domestic animals, pets. The sound class, Domestic animals, pets is a predecessor to both Bark and Meow, so by excluding it, the sounds previously identified as Bark and Meow are now both identified as the predecessor of Domestic animals, pets, which is Animal.

sounds = classifySound(audioIn,fs,"ExcludedSounds","Domestic animals, pets")

%
% Call classifySound again and set ExcludedSounds to Animal. The sound class Animal has no predecessors.

sounds = classifySound(audioIn,fs,"ExcludedSounds","Animal")

%
% If you want to avoid detecting Meow and its predecessors, but continue detecting successors under the same predecessors, use the IncludedSounds option. Call yamnetGraph to get a list of all supported classes. Remove Meow and its predecessors from the array of all classes, and then call classifySound again.

[~,classes] = yamnetGraph;
classesToInclude = setxor(classes,["Meow","Cat","Domestic animals, pets","Animal"]);
sounds = classifySound(audioIn,fs,"IncludedSounds",classesToInclude)

% Copyright 2020 The MathWorks, Inc.