Azure 网站上的 NAudio 转换

NAudio Conversion on Azure website

我是音频编程的新手,我正在使用 NAudio 在我的 Web 应用程序后端上转换 mp3 文件。 NAudio 转换在 ApiController 中处理。当我 运行 我的应用程序在本地时,文件会按预期进行转换,但是当我将网站发布到 Azure 时,出现错误。我调试了站点,发现在读取文件时出现错误。

Mp3FileReader reader = new Mp3FileReader(filePath);

我收到错误 NoDriver calling acmFormatSuggest。这只是在转换之前读取文件。

我已在线搜索错误,但 none 的答案解决了我的问题。我尝试了 here 等提供的解决方案,但 none 似乎适用于我的问题。

任何人都可以告诉我为什么这可以在我的本地 IIS 网站上运行但不能在我的 azure 网站上运行吗?我该如何解决这个问题?

据此 post

WaveFormatConversionStream makes use of the ACM codecs installed on your machine. It starts by asking if there is any ACM codec installed that can convert from the source to the target format. It would seem that you are missing an MP3 codec on the target machine.

这就回答了问题。默认情况下,您的 Azure Web 应用程序中没有安装 ACM 编解码器。 Azure Web App 在 Windows 的完整版本上并不 运行,就像你在 运行 本地一样。

根据 this post,您的另一个选择是使用 Azure Web 角色和自定义启动脚本进行部署。

Automatically (Azure deployments):

Add these commands to a Startup.cmd startup task in Azure for your role:

> echo Begin Install Desktop Experience Feature (for sound codec) >>
> startup.log ServerManagerCMD.exe -install Desktop-Experience -restart
> -resultPath     desktopexperience_results.xml REM This return code indicates the feature is already installed. Reset the errorlevel to
> zero using the verify command. IF %ERRORLEVEL% EQU 1003 (
>     echo Windows feature is already installed >> startup.log
>     VERIFY > NUL ) echo End Install Desktop Experience Feature >> startup.log 

请注意,此脚本 returns 结果很重要

code (%ERRORLEVEL%) of zero (which the above will do, bar any actual problems).

The ServerManagerCMD will return a non-zero error code when it does not need to install the feature (perhaps because it was already installed from a previous Startup.cmd run), so we explicitly need to check for that code (1003) and silence it using VERIFY >

对于未来的读者,NAudio 转换对我来说在 Azure 网站和 Azure Web 角色上都不起作用。我最终使用 CloudConvert api and a .NET Wrapper 进行音频转换。这很好用!

但是an increased cost可以上传更多的文件。