Ankilan/src/actions/api/word-sound.js

13 lines
349 B
JavaScript
Raw Normal View History

const getAudio = async word => {
2020-03-20 15:19:09 +00:00
const site = await fetch(`https://www.lexico.com/definition/${word}`, {
2020-03-13 20:45:31 +00:00
method: 'GET',
headers: {'Content-Type': 'text/html'},
});
const html = await site.text();
const getSrc = new RegExp('<audio.+?src="(.+?)".+?/?>');
const src = html.match(getSrc)[1];
return src;
};
export default getAudio;