-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from noblesamurai/init
Initial implementation.
- Loading branch information
Showing
6 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const util = require('util'); | ||
const exec = util.promisify(require('child_process').exec); | ||
const tempy = require('tempy'); | ||
|
||
/** | ||
* @param {string} filename | ||
* @param {object} opts | ||
* @param {string} opts.ffmpeg ffmpeg full path | ||
* @param {string} opts.sox sox full path | ||
*/ | ||
module.exports = async function sox (filename, opts = {}) { | ||
const { ffmpeg = 'ffmpeg', sox = 'sox' } = opts; | ||
const tempfile = tempy.file({ extension: 'wav' }); | ||
await exec(`${ffmpeg} -i ${filename} ${tempfile}`); | ||
const { stderr } = await exec(`${sox} ${tempfile} -n stat`); | ||
const rms = stderr.match(/RMS[ ]+amplitude:[ ]+([\d.]+)/); | ||
const max = stderr.match(/Maximum[ ]+amplitude:[ ]+([\d.]+)/); | ||
return rms && max && { rms: parseFloat(rms[1]), max: parseFloat(max[1]) }; | ||
}; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const expect = require('chai').expect; | ||
const path = require('path'); | ||
const rmsAmplitude = require('..'); | ||
|
||
describe('rms-amplitude', function () { | ||
it('gives the RMS amplitude of an audio file', async function () { | ||
const result = await rmsAmplitude(path.join(__dirname, 'fixtures/Allure10.mp3')); | ||
expect(result.max).to.be.a('number'); | ||
expect(result.rms).to.be.a('number'); | ||
expect(result.rms).to.be.lessThan(result.max); | ||
}); | ||
it('handles a .mp4 file', async function () { | ||
const result = await rmsAmplitude(path.join(__dirname, 'fixtures/user_video-30.mp4')); | ||
expect(result.max).to.be.a('number'); | ||
expect(result.rms).to.be.a('number'); | ||
}); | ||
}); |