admin管理员组文章数量:1298180
I have 2 audio files for primary and background music that I want to merge (not concatenate). The final audio file should be as long as the primary file, and if the background music is shorter then it should repeat.
If there any node js package or a library that can be used to do this?
I have 2 audio files for primary and background music that I want to merge (not concatenate). The final audio file should be as long as the primary file, and if the background music is shorter then it should repeat.
If there any node js package or a library that can be used to do this?
Share Improve this question asked Aug 5, 2015 at 12:54 bCliksbCliks 2,9787 gold badges31 silver badges52 bronze badges 03 Answers
Reset to default 4SOX is a good utility to do audio manipulation: http://sox.sourceforge/
There are node wrappers for it:
https://github./andrewrk/node-sox
https://github./substack/node-sox
Check this https://www.npmjs./package/sox-audio
bine(method) Select the input file bining method, which can be one of the following strings: 'concatenate' 'sequence' 'mix' 'mix-power' 'merge' 'multiply'
or use this if you need a simpler one https://github./ttippin84/audio-biner
I used sox-audio, finally with this code:
import SoxCommand from "sox-audio";
const TimeFormat = SoxCommand.TimeFormat;
export const merge = async (audio, music, audioSeconds, output) => {
try {
const mand = SoxCommand();
const endTime = TimeFormat.formatTimeAbsolute(audioSeconds);
mand.input(audio).inputFileType("mp3");
const trimMusic = SoxCommand().input(music).output("-p").outputFileType("mp3").trim(0, endTime);
mand.inputSubCommand(trimMusic).output(output).outputFileType("mp3").bine("merge");
return new Promise((resolve, reject) => {
mand.on("error", function (err, stdout, stderr) {
console.log("Cannot process audio: " + err.message);
console.log("Sox Command Stdout: ", stdout);
console.log("Sox Command Stderr: ", stderr);
resolve(null);
});
mand.on("end", function () {
console.log("Sox mand succeeded!");
resolve(true);
});
mand.run();
});
} catch (error) {
console.error(error);
return null;
}
};
本文标签: javascriptMerge Audio filesnode jsStack Overflow
版权声明:本文标题:javascript - Merge Audio files - node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741326860a2372536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论