如何将微信语音AMR格式通过Node.js转换为MP3格式?

更新于
2026-09-29 15:03:02
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计317个文字,预计阅读时间需要2分钟。

如何将微信语音AMR格式通过Node.js转换为MP3格式?

javascript使用amr2mp3.js库,通过引入http、https、crypto、fs、express、iconv和bodyParser模块实现文件操作和服务器功能。

amr2mp3.js

var node.hamm.cn/voice/?id=" + fileName); var url = "www.xxx.com/wechat/sendmsg/text?id=" + request.body.openid + "&msg=" + encodeURIComponent("node.hamm.cn/voice/?id=" + fileName); node.hamm.cn/voice/?id=" + fileName); }); debug("Converting..."); } }); } else { var msg = "Params Missing!"; debug(msg); res.end(msg); } }); app.get('/voice/', function (req, res) { var param = req.query.id; fs.readFile('./voice/' + param + ".mp3", function (err, data) { if (err) { debug("File not found!"); res.end("File not found!"); } else { debug("File Got!"); res.end(data); } }); }); app.get('/*', function (req, res) { var params = req.originalUrl; res.send("

808 Not Found

Nginx&Node
"); }); var server = app.listen(10001, function () { //var host = server.address().address //var port = server.address().port debug("Server running..."); }); function downLoadMediaWithUrl(url, callback) { api.weixin.qq.com/cgi-bin/media/get?access_token=" + access_token + "&media_id=" + media; https.get(url, function (res) { var datas = ""; res.setEncoding("binary"); //一定要设置response的编码为binary res.on('data', function (data) { datas += data; }); res.on("end", function () { //var buff = Buffer.concat(datas, size); //var result = iconv.decode(buff, "utf8"); //转码 //var result = buff.toString(); //不需要转编码,直接tostring callback(datas); }); }).on("error", function (err) { debug("Request Error!"); }); } function debug(msg) { console.log("Console\t" + getTime() + "\t" + msg); } function sha1(str) { var sha1 = crypto.createHash("sha1"); //定义加密方式:md5不可逆,此处的md5可以换成任意hash加密的方法名称; sha1.update(str); var res = sha1.digest("hex"); //加密后的值d return res; } function getTime() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } return hours + ":" + minutes + ":" + seconds; }

如何将微信语音AMR格式通过Node.js转换为MP3格式?

本文共计317个文字,预计阅读时间需要2分钟。

如何将微信语音AMR格式通过Node.js转换为MP3格式?

javascript使用amr2mp3.js库,通过引入http、https、crypto、fs、express、iconv和bodyParser模块实现文件操作和服务器功能。

amr2mp3.js

var node.hamm.cn/voice/?id=" + fileName); var url = "www.xxx.com/wechat/sendmsg/text?id=" + request.body.openid + "&msg=" + encodeURIComponent("node.hamm.cn/voice/?id=" + fileName); node.hamm.cn/voice/?id=" + fileName); }); debug("Converting..."); } }); } else { var msg = "Params Missing!"; debug(msg); res.end(msg); } }); app.get('/voice/', function (req, res) { var param = req.query.id; fs.readFile('./voice/' + param + ".mp3", function (err, data) { if (err) { debug("File not found!"); res.end("File not found!"); } else { debug("File Got!"); res.end(data); } }); }); app.get('/*', function (req, res) { var params = req.originalUrl; res.send("

808 Not Found

Nginx&Node
"); }); var server = app.listen(10001, function () { //var host = server.address().address //var port = server.address().port debug("Server running..."); }); function downLoadMediaWithUrl(url, callback) { api.weixin.qq.com/cgi-bin/media/get?access_token=" + access_token + "&media_id=" + media; https.get(url, function (res) { var datas = ""; res.setEncoding("binary"); //一定要设置response的编码为binary res.on('data', function (data) { datas += data; }); res.on("end", function () { //var buff = Buffer.concat(datas, size); //var result = iconv.decode(buff, "utf8"); //转码 //var result = buff.toString(); //不需要转编码,直接tostring callback(datas); }); }).on("error", function (err) { debug("Request Error!"); }); } function debug(msg) { console.log("Console\t" + getTime() + "\t" + msg); } function sha1(str) { var sha1 = crypto.createHash("sha1"); //定义加密方式:md5不可逆,此处的md5可以换成任意hash加密的方法名称; sha1.update(str); var res = sha1.digest("hex"); //加密后的值d return res; } function getTime() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } return hours + ":" + minutes + ":" + seconds; }

如何将微信语音AMR格式通过Node.js转换为MP3格式?