使用Fbla/Fblabla構建查詢有點困難,但可以從dictionary.com獲取所需的鏈接。像這樣的東西似乎工作:
word = 'supercalifragilisticexpialidocious'; % the word that is to be found
% build the query for dictionary.com by adding the word and read the url
r = urlread(sprintf('http://dictionary.reference.com/browse/%s',word));
% examine the resulting string that contains the html
try
% find the index of a certain matching sentence that indicates the beginning and end of the query
matchIdx = strfind(r,'audio/ogg"> <source src="http://static.sfdict.com/staticrep/dictaudio/');
endIdx = strfind(r, '.mp3"></a>');
% some tuning with indexes results in the exact url that needs to be called
% hopefully, the matchIdx and endIdx are found only once - if more, there is an error
mp3url = r(matchIdx+141:endIdx+3);
% if there is no match, the url is empty, which is also undesirable
assert(~isempty(mp3url));
catch e
% catch the above errors (the mp3url cannot be constructed or is empty), and maybe others
% (if this becomes a function, some nice pointers of what went wrong should be added)
error('Could not find url.');
end
% query for the mp3 and store the result
file = 'temp.mp3';
urlwrite(mp3url,file);
% read the just stored file and play!
[x,Fs] = audioread(file);
soundsc(x,Fs);
這是非常有用的 - 我試圖弄清代碼 - 你可以添加一些評論,指導我通過它? (仍然不流利matlab)。如何在哪裏獲得音頻文件的鏈接? – Cerberus 2014-10-03 15:42:35
好的 - 完成了。如需更多幫助,請閱讀[urlread]上的matlab手冊(http://www.mathworks.nl/help/matlab/ref/urlread.html),[audioread](http://www.mathworks.nl/help/) matlab/ref/audioread.html),[soundsc](http://www.mathworks.nl/help/matlab/ref/soundsc.html)等。 – MeMyselfAndI 2014-10-03 15:56:10
再次感謝!我正在使用MATLAB R2010a,並沒有「audioread」功能,我應該如何播放MP3文件,有什麼建議嗎? – Cerberus 2014-10-04 15:23:26