나는 이것이 오래 전에 질문을 받았다 볼 수 있지만, 나는 비슷한 문제에왔다, 내가하지만 오디오 태그와 함께, 그것은 크롬과 파이어 폭스에 대한 작동하게 할 수 있었다. 여기
는 나를 위해 트릭을 만든 코드 ...
var sayIt;
function createSayIt() {
// Tiny trick to make the request to google actually work!, they deny the request if it comes from a page but somehow it works when the function is inside this iframe!
//create an iframe without setting the src attribute
var iframe = document.createElement('iframe');
// don't know if the attribute is required, but it was on the codepen page where this code worked, so I just put this here. Might be not needed.
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-pointer-lock');
// hide the iframe... cause you know, it is ugly letting iframes be visible around...
iframe.setAttribute('class', 'hidden-iframe')
// append it to the body
document.body.appendChild(iframe);
// obtain a reference to the contentWindow
var v = iframe.contentWindow;
// parse the sayIt function in this contentWindow scope
// Yeah, I know eval is evil, but its evilness fixed this issue...
v.eval("function sayIt(query, language, cb) { var audio = new Audio(); audio.src = 'http://translate.google.com/translate_tts?ie=utf-8&tl=' + language + '&q=' + encodeURIComponent(query); cb && audio.addEventListener('ended', cb); audio.play();}");
// export it under sayIt variable
sayIt = v.sayIt;
}
내가 우회 할 수 있었다고 생각 나는 여기
http://jsfiddle.net/royriojas/SE6ET/
을 만든 데모 페이지입니다입니다 제한. 앞으로 내가 모르는이 해킹을 잠재적으로 수정할 수 있습니다. 사실
당신은 또한 Text2Speech HTML5 API를 사용하려고 할 수 있습니다 ... 그렇지 않은 희망하지만,
IE 11이 해킹 작동하지 않습니다 ... 아직 시간이 매우 젊은이다 미래 나는 그것을 고치려고 노력할 수도있다