I am looking for a guide on how to use google text to speech service in Java script. Currently I am using this:
var src = "https://translate.google.com/translate_tts?key='+key +'8&total=1&idx=0&textlen=32&client=tw-ob&q=" + encodeURIComponent(txt) + "&tl=" + language;
console.log(src)
var vid = $('#Audio');
vid.get(0).pause();
$('#Audio').attr('src', src);
vid.get(0).load();
vid.get(0).play();
The main issue is that this code is not stable. Sometimes it returns empty audio and sometimes it works for same request.
It seems this service is not added to google-cloud-platform. It was before under google translate but not anymore. using the link in the question will work if there is user interaction , like pressing a button,. However,calling it dynamically in the code without user interaction will result in an empty audio file. It looks like someway from google to prevent denial of service attack. I ended up using speechSynthesis for languages which are supported in speechSynthesis and third party products for other languages such as Arabic.