├── .babelrc ├── src ├── amr │ ├── test.amr │ └── abcdef 1544497148360.1526463056869.amr └── mp3 │ ├── 12345.mp3 │ ├── test.mp3 │ └── abcdef 1544497148360.1526463056869.mp3 ├── .travis.yml ├── package.json ├── .gitignore ├── test └── test.js ├── LICENSE ├── app.js └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } -------------------------------------------------------------------------------- /src/amr/test.amr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Binaryify/amrToMp3/HEAD/src/amr/test.amr -------------------------------------------------------------------------------- /src/mp3/12345.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Binaryify/amrToMp3/HEAD/src/mp3/12345.mp3 -------------------------------------------------------------------------------- /src/mp3/test.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Binaryify/amrToMp3/HEAD/src/mp3/test.mp3 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | 5 | - 4.0 6 | - 6.2 7 | -------------------------------------------------------------------------------- /src/amr/abcdef 1544497148360.1526463056869.amr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Binaryify/amrToMp3/HEAD/src/amr/abcdef 1544497148360.1526463056869.amr -------------------------------------------------------------------------------- /src/mp3/abcdef 1544497148360.1526463056869.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Binaryify/amrToMp3/HEAD/src/mp3/abcdef 1544497148360.1526463056869.mp3 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amrToMp3", 3 | "version": "2.0.0", 4 | "description": "", 5 | "main": "build/app.js", 6 | "scripts": { 7 | "test": "node ./test/test", 8 | "build": "babel app.js -d build/" 9 | }, 10 | "keywords": [ 11 | "amr", 12 | "amr to mp3", 13 | "wechat amr" 14 | ], 15 | "author": "traveller", 16 | "license": "MIT", 17 | "dependencies": { 18 | "ffmpeg-static": "^4.2.7" 19 | }, 20 | "devDependencies": { 21 | "babel-cli": "^6.26.0", 22 | "babel-core": "^6.26.3", 23 | "babel-preset-es2015": "^6.9.0" 24 | }, 25 | "repository": "Binaryify/amrToMp3" 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | 4 | let amrToMp3 = require('../build/app'); 5 | amrToMp3('src/amr/test.amr') 6 | .then(data => { 7 | console.log(data); // ./src/mp3/test.mp3 8 | //...业务代码 9 | }) 10 | .catch(err => { 11 | console.log(err); 12 | }); 13 | 14 | // test path have span 15 | amrToMp3('src/amr/abcdef 1544497148360.1526463056869.amr') 16 | .then(data => { 17 | console.log(data); // ./src/mp3/test.mp3 18 | //...业务代码 19 | }) 20 | .catch(err => { 21 | console.log(err); 22 | }); 23 | 24 | amrToMp3('src/amr/abcdef 1544497148360.1526463056869.amr', undefined, '12345') 25 | .then(data => { 26 | if (!fs.existsSync('src/mp3/12345.mp3')) { 27 | throw new Error('outputName Error'); 28 | } else { 29 | console.log(data); // ./src/mp3/test.mp3 30 | //...业务代码 31 | } 32 | }) 33 | .catch(err => { 34 | console.log(err); 35 | }); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 阿发 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const exec = require('child_process').exec; 2 | const path = require('path'); 3 | const ffmpegPath = require('ffmpeg-static'); 4 | 5 | function amrToMp3(filepath, outputDir = './src/mp3', outputName) { 6 | return new Promise((resolve, reject) => { 7 | const { ext, name: filename } = path.parse(filepath); 8 | // http://xmqvip.oss-cn-hangzhou.aliyuncs.com/other/images/2018/12/11/1544497148360.1526463056869.amr 9 | if (ext.toLocaleLowerCase() != '.amr') { 10 | console.log(`${filepath} is not a .amr file`); 11 | reject(new Error(`${filepath} is not a .amr file`)); 12 | return; 13 | } 14 | const _outputName = outputName || filename; 15 | const cmdStr = `${ffmpegPath} -y -i "${path.normalize(filepath)}" -acodec libmp3lame -ar 24000 -vol 500 -ab 128 "${path.join(outputDir, _outputName + '.mp3')}"`; 16 | exec(cmdStr, (err, stdout, stderr) => { 17 | if (err) { 18 | // console.log('error:' + stderr); 19 | reject(new Error('error:' + stderr)); 20 | } else { 21 | resolve(`${outputDir}/${_outputName}.mp3`); 22 | // console.log(`transform to mp3 success! ${path.normalize(filepath)}->${path.join(outputDir, _outputName + '.mp3')}`); 23 | } 24 | }); 25 | }); 26 | } 27 | 28 | module.exports = amrToMp3; 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # amrToMp3 2 | amr to mp3 nodeJS module 3 | 4 | amr音频转mp3模块 5 | 6 |
13 | 14 | ## Installation 15 | This module is installed via npm: 16 | ``` 17 | $ npm install amrToMp3 18 | ``` 19 | ## api 20 | ```js 21 | amrToMp3(sourcePath[,outputPath, outputName]) //outputPath default:./src/mp3/ 22 | ``` 23 | 24 | ## usage 25 | js 26 | ```js 27 | const amrToMp3 = require('amrToMp3') 28 | amrToMp3('src/amr/test.amr') 29 | .then(function (data) { 30 | console.log(data) // ./src/mp3/test.mp3 31 | //...some code 32 | }) 33 | .catch(function (err) { 34 | console.log(err) 35 | }) 36 | ``` 37 | or 38 | ```js 39 | const amrToMp3 = require('amrToMp3') 40 | const data = await amrToMp3('src/amr/test.amr') // ./src/mp3/test.mp3 41 | console.log(data) 42 | ``` 43 | 44 | ## support 45 | * 64 bit Mac OSX 46 | * 64 bit Linux 47 | * 32 bit Linux 48 | * 64 bit Windows 49 | * 32 bit Windows 50 | 51 | ## test 52 | ``` 53 | $ npm test 54 | ``` 55 | 56 | ## build 57 | ``` 58 | $ npm run build 59 | ``` 60 | --------------------------------------------------------------------------------