如何在Windows Server 2012 R2上运行Microsoft.CognitiveServices.Speech

我需要将语音从wav文件转换为文本。 所以我从Quickstart下载了示例C#代码项目:使用Speech service C#SDK页面识别语音 ,并按照页面上的说明进行操作。

它适用于Windows 10,但我需要该项目在Windows Server 2012 R2上运行,它在Windows Server 2012 R2上不起作用。

当我在Windows Server 2012 R2上运行它时,我按3键进行3.语音识别和文件输入选项。 但是当它尝试执行以下代码时(具有有效的订阅和区域值)

var factory = SpeechFactory.FromSubscription("YourSubscriptionKey", "YourServiceRegion"); 

抛出以下exception:

发生System.TypeInitializationException HResult = 0x80131534 Message =“Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE”的类型初始值设定项引发exception。 Source = Microsoft.CognitiveServices.Speech.csharp StackTrace:at Microsoft.CognitiveServices.Speech.Internal.SpeechFactory.FromSubscription(String subscription,String region)中的Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE.SpeechFactory_FromSubscription(String jarg1,String jarg2)at at Microsoft.CognitiveServices.Speech.SpeechFactory.FromSubscription(String subscriptionKey,String region)at MicrosoftSpeechSDKSamples.SpeechRecognitionSamples.d__2.MoveNext()in C:\ temp \ csharp_samples \ speech_recognition_samples.cs:line 86

内部exception1:TypeInitializationException:’SWIGExceptionHelper’的类型初始值设定项引发exception。

内部exception2:DllNotFoundException:无法加载DLL’Microsoft.CognitiveServices.Speech.csharp.bindings.dll’:找不到指定的模块。 (HRESULTexception:0x8007007E)

我认为Microsoft.CognitiveServices.Speech.csharp.bindings.dll不喜欢在Windows Server 2012 R2上运行,因为它存在于bin文件夹中(并且不会丢失)并且可以在Windows 10上运行。我编写了以下代码在一个小的Hello World控制台项目中,它抛出了在Windows Server 2012 R2上运行的相同exception。

 class Program { [DllImport("Microsoft.CognitiveServices.Speech.csharp.bindings.dll", CharSet = CharSet.None, EntryPoint = "CSharp_MicrosoftfCognitiveServicesfSpeechfInternal_TRANSLATION_LANGUAGE_RESOURCE_SCOPE_SPEECH_get___", ExactSpelling = false)] public static extern int TRANSLATION_LANGUAGE_RESOURCE_SCOPE_SPEECH_get(); static void Main(string[] args) { int test = TRANSLATION_LANGUAGE_RESOURCE_SCOPE_SPEECH_get(); Console.WriteLine($"API value: {test}"); } } 

我尝试以管理员身份运行,以防它是一个许可的事情。 但那没有做任何事情。

有人可以帮助我吗?告诉我在Windows Server 2012 R2上运行语音服务示例需要做些什么?

安装Visual Studio 2017的最新Microsoft Visual C ++ Redistributable应该修复它,请参阅https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads 。

(我们会尽快更新文档)

目前,SDK对Windows Media Foundation具有很强的依赖性。 你的服务器镜像上是否有以下dll:Ksuser.dll,Mf.dll,Mfcore.dll,Mfplat.dll,Mfreadwrite.dll?

使用.NET Framework 4.7.1进入此问题,但它不会抛出exception并在.NET Core 2.0中运行

执行以下行时,在.NET中出现此错误

 var recognizer = factory.CreateSpeechRecognizer(); 

{“Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE’的类型初始化程序引发了exception。”}

.NET Core 2.0中完全相同的代码创建了工厂。 还要确保安装2017年最新的Visual C ++ Redistributables

在Build> Configuration Manager中检查项目的平台设置。
它必须设置为x64或x86,而不是AnyCpu。