Html5 audio tag not working in Local IIS for Google translate_tts

339 views Asked by At

Trying to use google's translate_tts as my fallback if the browser doesn't support speechSynthesis for my project.

Now I am having some trouble with getting the html5 audio working properly. Been scratching my head and googling all day on why it wasn't working for me. Then I came across some articles/forums saying that it's something to do with IIS. So I did a test code outside my site to see what happens, and was surprised this worked properly! But when using the same code in my original project which is running in IIS it doesn't work. AND it works when using IIS EXPRESS. I check the MIME types in IIS and mpeg and mp3 are there.

enter image description here

Even doing it in javascript doesn't work in IIS.

TextToSpeech.Audio = document.createElement("AUDIO");
TextToSpeech.Audio.src = url;
TextToSpeech.Audio.playbackRate = 1;
TextToSpeech.Audio.preload = 'auto';
TextToSpeech.Audio.volume = 1; // 0 to 1;
TextToSpeech.Audio.addEventListener('ended', function () {
        //i have some code here...  
});
TextToSpeech.Audio.addEventListener('error', function (error) { });
TextToSpeech.Audio.play();

Has anyone encountered this issue and happened to resolve it? Your help will be much appreciated, Thanks!

UPDATE: After some more googling, this might be because I am calling it from within my site hosted in IIS which has a proper hostname and my IIS Express runs the site in localhost:PORT which Google sees as noreferrer?

1

There are 1 answers

0
Barry On

starting some time in the last few days, google seems to have placed a 'captcha' on this service and made it so that it can no longer be called by a server. so this may all be moot.

it used to be you could ONLY call it as a noreferrer, so i don't think noreferrer is your issue (or may be the least of your issues starting a few days back). one way to workaround the issue in fact was to add ref='noreferrer' to your link.

and this may be your initial issue: using wget, you had to use the -U Mozilla option which makes wget appear to be a browser. if you called the url without that, it didn't return anything. so if there is a way to make your IIS look like a browser when calling the google url, that may work.

this link google text-to-speech artile still does work in a browser, maybe that will help you use it the way you want.

however... starting july 28th, i get a '503 service not available' after using it for years with wget on my linux server. could be because it's metered and i've overrused it... i hope it comes back on. i only use it about 100x/day.

they always said it was 'not public' but it is widely used that way...

so that could be related if you're still trying to call it from IIS which i would think behaves similarly to calling it from a linux server.