firstly, I have to say sorry for my bad English :)
Anyway, I'm going to develop a simple website that users can upload their audio files and play others' files. I planed to use Node.js, and HTML5 built-in audio tag to play the files. I have never used the audio tag, so I wondered if the tag really works fine, so today I lightly wrote a simple code and played a mp3 file and I got a problem, which is that the mp3 file wasn't be played using the tag. I realized the audio tag cannot play audio files above bitrate 128kbps. so now, I need a way of auto-converting from more than 128kbps to 128kbps, in javascript(using Node.js).
I've never used Node.js, so I never know how to do this. The things I want to know are that it is possible and it is easy.
Anyone give me how or where to find the solution please.
Thanks to read my bad-English question anyway.
Good luck :)
You can do this easily by spawning something like SoX, ffmpeg, etc. Here's an example using SoX (on Debian/Ubuntu you'll need to make sure libsox-fmt-mp3
or libsox-fmt-all
is installed for mp3 support):
var spawn = require('child_process').spawn;
require('http').createServer(function(req, res) {
if (req.url === '/audio') {
res.statusCode = 200;
var cp = spawn('sox', ['/path/to/input.mp3', '-C', '128', '-']);
return cp.stdout.pipe(res);
}
res.statusCode = 404;
res.end();
}).listen(8000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.