How to play Audio File
1 view (last 30 days)
Show older comments
B.k Sumedha
on 4 Jun 2015
Commented: B.k Sumedha
on 8 Jun 2015
A= testing;
B= [ten;
twenty;
fifty;
hundered;
fivehundered;
thousand];
G={'ten';
'twenty';
'fifty';
'hundered';
'five_hundered';
'thousand'};
class=knnclassify(A,B,G);
disp(class);
pathss=class
for index = 1:numel(pathss)
temp=pathss{index}
end
% [rows]=testing;
% for i=1:rows
if (temp=='ten')
a=wavread('stopsign.wav');
wavplay(a,44100);
% end
% end
% TF=strcmp(temp,ten)
% for index = 1:numel(pathss)
% temp1=pathss{index}
%
elseif (temp=='twenty')
a=wavread('crossroad.wav');
wavplay(a,44100);
elseif (temp=='fifty')
a=wavread('crossroad.wav');
wavplay(a,44100);
elseif (temp=='hundered')
a=wavread('crossroad.wav');
wavplay(a,44100);
elseif (temp=='five_hundered')
a=wavread('crossroad.wav');
wavplay(a,44100);
elseif (temp=='thousand')
a=wavread('crossroad.wav');
wavplay(a,44100);
end
end
This is a knnclassifer which i am using.It gets classifed into correct group but the audio file doesnt play.Whats the problem in here?
0 Comments
Accepted Answer
Walter Roberson
on 4 Jun 2015
You should not be using "==" to compare strings. You should be using strcmp()
3 Comments
Walter Roberson
on 6 Jun 2015
Do not name a variable "class". "class" is an important MATLAB routine.
Your code
for index = 1:numel(pathss)
temp=pathss{index}
end
assigns to temp and overwrites the result in the next iteration. The result is the same as if you had just done
temp = pathss{end};
The results would be the same if you only have a single sample in "testing" to classify, but in that case you would simply use
temp = pathss{1};
If you do have multiple samples to classify, then why would you be choosing the last one to play audio about? If you are only going to use the information about the last sample then why bother to classify the other samples?
What you have in your comments does not concern me. Your code tries to compare strings using "==", and that is going to fail.
You should be converting your code to use audioread() and audioplay() instead of wavread() and wavplay(), but that would not affect whether the audio comes out in existing releases. Having the wrong comparison operator for strings would cause audio to fail to come out, as MATLAB will error() out the code when you try to use "==" to compare strings of different lengths.
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!