Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

javascript - Combining audio files in HTML

I have a HTML page which has two audio files ABC.mp3 of 30 sec and XYZ.mp3 of 15 sec. I need to combine these two files in such a manner that I get a new file PQR.mp3 of 30 sec (AND NOT 45 sec) which has one file overlapped/merged over the other. Any kind of plug-ins, javascript etc. will be helpful, keeping HTML and HTML5 under consideration.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Simple answer: No. Neither Javascript nor HTML5 have the power to do this. You will need server side tools to do this. For example ffmpeg and LAME in case of MP3.

If you really need to do such manipulations on a HTML basis, the only way is to bind these programms to a php script or NodeJS server that then starts a job to do what you want to do. Nevertheless you would have to write bash script or cronejobs to do so.

edit

For nodeJS you will need to write your own node server application. The application then should be using socketIO and node-fluent-ffmpg which also has lame with it. The app could look like this

server:

var io = require('socket.io').listen(80);
var exec = require('child_process').exec;
io.sockets.on('connection', function (socket) {
  socket.on('mergeFiles', function (data) {
    var firstFile = data.firstFile;
    var secondFile = data.secondFile;

    //do ffmpg stuff by executing a shell script
    execString = "./yourscript.sh " + firstFile + " " + secondFile

    function puts(error, stdout, stderr) { sys.puts(stdout) }
    exec(execString , puts);
});

client:

<script src="/socket.io/socket.io.js"></script>
<script>
  var firstFile = ABC.mp3;
  var secondFile = XYZ.mp3;

  var socket = io.connect('http://localhost');
  socket.emit('mergeFiles', { firstFile: firstFile, secondFile: secondFile });
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...