オックスフォードの英英辞典から英語の発音を取得
英語の勉強をしていて、単語の発音をさせれたらなぁということでオックスフォードの英英辞典 の音声を取得してみました。Speach APIなどを利用してもいいのですが、発音がちょっと違うかな、と 思ったので、、、
他のサイトのHTMLをjQueryで取得するために、jquery.xdomainajax.jsを読み込ませます。
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script> <script src="jquery.xdomainajax.js"></script>
あとは、下記のような関数を作って、英単語をしゃべらせます。
function speak(word){
$.ajax({
type: 'GET',
url: 'http://www.oxfordlearnersdictionaries.com/definition/english/'+word+'?q='+word,
dataType: 'html',
crossDomain: true,
success: function(data) {
mp3=$(data.responseText).find("[title=' pronunciation American']").attr('data-src-mp3');
alert(mp3);
var audio = new Audio();
audio.src = mp3;
audio.play();
alert(mp3);
}
});
}
speak("hello");
