How to play Audio File
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2015년 6월 4일
You should not be using "==" to compare strings. You should be using strcmp()
댓글 수: 3
Walter Roberson
2015년 6월 6일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!