我正在开发一个网页,用户将选择两个音频文件,应用程序将加入两个音频文件并将其作为单个输出音频文件。我在后端使用nodejs,在客户端使用angularjs。我怎样才能达到这个要求?我经历过许多图书馆都不适合它。
答案 0 :(得分:0)
此刻,我正在查看类似的用例。这些库并不是很好,因为大多数需要在服务器环境中安装一个大程序。例如:
或者你不需要输出音频可以搜索,你可以简单地用流做。概念:
var fs = require('fs')
var writeStream = fs.createWriteStream('outputAudio.mp3'); // Or whatever you want to call it
// Input files should be an array of the paths to the audio files you want to stitch
recursiveStreamWriter(inputFiles) {
if(inputFiles.length == 0) {
console.log('Done!')
return;
}
let nextFile = inputFiles.shift();
var readStream = fs.createReadStream(nextFile);
readStream.pipe(writeStream, {end: false});
readStream.on('end', () => {
console.log('Finished streaming an audio file');
recursiveStreamWriter(inputFiles);
});
}
这很有效,过渡很好,但音频播放器很难寻找音频。可以找到一个体面的完整示例here的递归流方法。
答案 1 :(得分:0)
作为一个例子,我将Iphone铃声与诺基亚铃声组合在一起,并将流式阅读器传送到写入流中。
//Created two reader streams
let readerstream1 = fs.createReadStream('iphone-6.mp3');
let readerstream2 = fs.createReadStream('Nokia.mp3');
// Created a write stream
let writestream = fs.createWriteStream('NewRingtone.mp3');
//just pipe one after the other
readerstream1.pipe(writestream);
readerstream2.pipe(writestream);