C# amr音频格式文件转换成mp3格式
微信语音都是使用amr音频格式的,这种格式文件放网页端是无法播放的,这时候需要后台转码成mp3格式
使用silk_v3_decoder.exe 和 lame.exe 文件通过cmd命令来转换成mp3格式
工具介绍: https://github.com/kn007/silk-v3-decoder/tree/master/windows
static void Main(string[] args) { //取得当前工作目录的完整限定路径 string currentWorkDir = Environment.CurrentDirectory; //silk文件完全路径 string silkFilePath = Path.Combine(currentWorkDir, "silk", "silk_v3_decoder.exe"); //lame文件完全路径 string lameFilePath = Path.Combine(currentWorkDir, "silk", "lame.exe"); //amr文件完全路径 string amrFilePath = Path.Combine(currentWorkDir, "amr", "msg.amr"); //pcm文件完全路径 string pcmFilePath = Path.Combine(currentWorkDir, "amr", "msg.pcm"); //mp3文件路径 string mp3FilePath = Path.Combine(currentWorkDir, "amr", DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3"); //先生成pcm文件 CmdHelper.ExecuteCmd(lamePath + "silk_v3_decoder.exe ", amrFilePath + " " + pcmFilePath); //生成mp3文件 CmdHelper.ExecuteCmd(lamePath + "lame.exe", " -r -s 24000 --preset voice " + pcmFilePath + " " + mp3FilePath); //删除临时pcm文件 if (File.Exists(pcmFilePath)) { File.Delete(pcmFilePath); } Console.WriteLine("Hello World!"); Console.ReadKey(); } /// <summary> /// 执行CMD命令返回信息 /// </summary> /// <param name="Command">命令</param> /// <returns>返回命令执行结果</returns> public static void ExecuteCmd(string fileName, string arg) { //创建一个ProcessStartInfo对象 使用系统shell 指定命令和参数 设置标准输出 var psi = new ProcessStartInfo(fileName, arg) { RedirectStandardOutput = true }; //var psi = new ProcessStartInfo(Command) { RedirectStandardOutput = true }; psi.UseShellExecute = false; //启动 var proc = Process.Start(psi); if (proc == null) { Console.WriteLine("Can not exec."); } else { //开始读取 using (var sr = proc.StandardOutput) { while (!sr.EndOfStream) { Console.WriteLine(sr.ReadLine()); } if (!proc.HasExited) { proc.Kill(); } } } }
执行完就会生成对应的mp3文件了
转自 http://www.mikeblog.cn/article/details/112
本文来自博客园,作者:jevan,转载请注明原文链接:https://www.cnblogs.com/DoNetCShap/p/18451970
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2022-10-08 Chrome内置谷歌翻译无法使用完美解决方法