【发布时间】:2020-12-11 05:26:24
【问题描述】:
我正在尝试使用 NAudio / NLayer.NAudioSupport 创建一个 Azure 函数,我可以在其中传入一个 URL(例如https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3),读取字节,并返回以 128Kbps 转换的 mp3 文件。但是,我目前收到一个异常说明:
System.Private.CoreLib:执行函数时出现异常:ReduceMp3Bitrate。 NAudio.Lame:不支持的编码格式MpegLayer3(参数
format)。
这是我当前的代码(第 5 行出现异常):
const string linkUrl = @"https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3";
var audioFile = new HttpClient().GetByteArrayAsync(linkUrl);
await using var ms = new MemoryStream(await audioFile);
var audioReader = new Mp3FileReader(ms);
await using var audioWriter = new LameMP3FileWriter(@"C:\temp\test.mp3", audioReader.Mp3WaveFormat, LAMEPreset.ABR_128);
await audioReader.CopyToAsync(audioWriter);
我认为问题出在audioReader.Mp3WaveFormat,但我不确定为什么会出现问题,因为它正在返回MpegLayer3。
我还尝试在 Windows 上运行的 .Net Framework 4.7 控制台应用程序上运行它(将 Azure Functions 排除在外),但仍然无法正常工作。
【问题讨论】:
标签: c# azure azure-functions mp3 naudio