一、音频文件格式转换
1)安装fluent-ffmpeg和ffmpeg插件
npm install fluent-ffmpeg;
npm install ffmpeg;
2)mp3转wav
test.js文件:
const ffmpeg = require('fluent-ffmpeg');ffmpeg('./test.mp3')
.format('wav')
.audioBitrate('16k')
.audioFrequency(16000)
.audioChannels(1)
.on('error', function(err){console.error('An error occurred: ', err);
})
.on('progress', (progress) => {console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', function(){console.log('Processing finished !');
})
.save('test.wav');
3) 执行转换
node test.js
运行test.js文件,报错“An error occurred: Error: Cannot find ffmpeg”,如下图所示
二、“An error occurred: Error: Cannot find ffmpeg”问题解决办法
1)安装’@ffmpeg-installer/ffmpeg’
npm install @ffmpeg-installer/ffmpeg
2)test.js文件修改
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);ffmpeg('./test.mp3')
.format('wav')
.audioBitrate('16k')
.audioFrequency(16000)
.audioChannels(1)
.on('error', function(err){console.error('An error occurred: ', err);
})
.on('progress', (progress) => {console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', function(){console.log('Processing finished !');
})
.save('test.wav');