4

I'm trying to make my website speaking some words, and I found that people often use google's translate_tts.

I've tried several ways to make the whole thing work, but still I can't make other's code work on my website (http://jsfiddle.net/n0e011t7/).

1) code from Text to speech using javascript and translate_tts

var sound = new Audio("http://translate.google.com/translate_tts?tl=sv&q=Testar");
sound.play();

That doesn't work for me - google returns 404. But if I open the same link from my code in the browser tab it loads (after page reload) the sound file and plays it.

Another three options I've tried but with the same reuslt:

2)

var nodeHTML = 
    '<audio src="http://translate.google.com/translate_tts?ie=UTF-8&q=hello&tl=en" autoplay="autoplay"></audio>';    
$("#sound").html(nodeHTML);

3)

var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://translate.google.com/translate_tts?tl=en&q=hello%20all');
audioElement.play();

4)

var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 
     'http://translate.google.com/translate_tts?tl=en&q=hello%20all');
audioElement.load()
audioElement.addEventListener("load", function() { 
  audioElement.play(); 
}, true);

Why does it work so strange, I mean, URL opens from a browser tab, but returns 404 if accessed from javascript?

Community
  • 1
  • 1
Dmitry Samoylov
  • 1,228
  • 3
  • 17
  • 27
  • I am seeing the same thing. But up until recently it was working. So clearly it was not blocked as you posted this in 2014 and mine was working in 2020. – Robert Kaucher Apr 28 '20 at 23:54

0 Answers0