gpt4 book ai didi

matlab - 如何在Matlab中从Dictionary.com下载MP3文件?

转载 作者:行者123 更新时间:2023-12-02 22:56:46 26 4
gpt4 key购买 nike

我正在编写一个脚本,该脚本需要下载和播放位于单独的.xls文件中的音频文件(基于词汇)。我想使用Dictionary.com下载正确发音的音频,但无法以系统的方式获取音频。

例如,单词“fatuity”的网址是

http://static.sfdict.com/staticrep/dictaudio/F00/F0058700.mp3

但是对于“乐趣”一词是

http://static.sfdict.com/staticrep/dictaudio/F04/F0416100.mp3

如何查询Dictionary.com并下载相关的音频?有什么建议么?

最佳答案

使用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 - 如何在Matlab中从Dictionary.com下载MP3文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26180990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com