2

I've googled now for half day and I guess the problem is that I don't know what the real problem is, so I fail to google it right!

Better to bring the code in:

<!doctype html>
<html>
<head><title>test</title></head>
<body>
<audio controls>
  <source src="http://translate.google.com/translate_tts?tl=en&q=Canada" type="audio/mpeg">
</audio>
</body>
</html>

If you save this as an html file and open it in a browser (tested on Firefox / Windows) the audio will be played with no problem.

Now I was to start a nodejs application and created this proof-of-concept server:

var express = require('express'),
app = express(),
bodyparser = require('body-parser'),
methodOverride = require('method-override'),
morgan = require('morgan'),
port = Number(process.env.PORT || 8090);

app.use(express.static(__dirname + '/public'));
app.use(bodyparser.json());
app.use(bodyparser.json({'type':'application/vnd.api+json'}));
app.use(bodyparser.urlencoded({'extended':'true'}));
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(morgan('dev'));

app.get('*', function(req, res){
    res.render('index');
});

app.listen(port, function(){
    console.log('running port: ' + port);
});

When I run it, I get these errors:

HTTP load failed with status 404. Load of media resource http://translate.google.com/translate_tts?tl=en&q=Maple failed.
All candidate resources failed to load. Media load paused.

I was thinking of it as a CORS problem, but then I proved to myself that it's a wrong guess very simply, by just brining a url to an mp3 file:

http://transom.org/wp-content/uploads/2004/03/stereo_96kbps.mp3

and it worked! If I provide a URL to an mp3 file, both simple html file and the one served by nodejs work fine. I then tried adding type to the audio source tag:

type="audio/mpeg"

which proved to have no effect here.

So what the real problem is please?

mscdex
  • 104,356
  • 15
  • 192
  • 153
Ariam1
  • 1,673
  • 2
  • 13
  • 32
  • This should work - the PHP equivalent worked for me - though this will use your app's bandwidth as the comment mentions: http://stackoverflow.com/a/25102474/1791525 – Daniel Sposito Jul 10 '15 at 07:16
  • Does this work in Safari for you? I just realized it's working great in Chrome and Firefox but not Safari. Unfortunately no error is thrown - the audio simply never plays. – Daniel Sposito Jul 24 '15 at 11:33
  • You know, I eventually could make the audio (from google translator) work only in Chrome! I guess that's a message from google: "if you want to use my paid service for free, at least promote my browser!". – Ariam1 Jul 25 '15 at 12:45

0 Answers0