【问题标题】:How to run Microsoft.CognitiveServices.Speech on Windows Server 2012 R2如何在 Windows Server 2012 R2 上运行 Microsoft.CognitiveServices.Speech
【发布时间】:2018-10-24 15:46:20
【问题描述】:

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

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

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

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

抛出以下异常:

发生 System.TypeInitializationException H结果=0x80131534 Message=“Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE”的类型初始化程序引发异常。 来源=Microsoft.CognitiveServices.Speech.csharp 堆栈跟踪: 在 Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE.SpeechFactory_FromSubscription(字符串 jarg1,字符串 jarg2) 在 Microsoft.CognitiveServices.Speech.Internal.SpeechFactory.FromSubscription(字符串订阅,字符串区域) 在 Microsoft.CognitiveServices.Speech.SpeechFactory.FromSubscription(字符串订阅密钥,字符串区域) 在 MicrosoftSpeechSDKSamples.SpeechRecognitionSamples.d__2.MoveNext() 在 C:\temp\csharp_samples\speech_recognition_samples.cs:line 86

内部异常 1: TypeInitializationException:“SWIGExceptionHelper”的类型初始化程序引发了异常。

内部异常 2: DllNotFoundException:无法加载 DLL 'Microsoft.CognitiveServices.Speech.csharp.bindings.dll':找不到指定的模块。 (HRESULT 异常:0x8007007E)

我认为 Microsoft.CognitiveServices.Speech.csharp.bindings.dll 不喜欢在 Windows Server 2012 R2 上运行,因为它存在于 bin 文件夹中(并且没有丢失)并且可以在 Windows 10 上运行。我写道在一个小小的 Hello World 控制台项目中添加以下代码,它在 Windows Server 2012 R2 上运行时引发了相同的异常。

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 上运行语音服务示例需要做什么?

【问题讨论】:

    标签: c# speech-recognition microsoft-cognitive


    【解决方案1】:

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

    (我们会尽快更新文档)

    【讨论】:

    • 我在 Windows Server 2012 R2 上安装了 Microsoft Visual C++ Redistributable for Visual Studio 2017 (x64),但它仍然抛出相同的异常。盒子上已经安装了 x86 版本。我在安装 x64 版本后也重新启动了服务器,但它仍然抛出异常。有什么我可以尝试的吗?
    【解决方案2】:

    目前,SDK 严重依赖于 Windows Media Foundation。您的服务器映像上是否有以下 dll:Ksuser.dll、Mf.dll、Mfcore.dll、Mfplat.dll、Mfreadwrite.dll?

    【讨论】:

    • 今天提供了 sdk 刷新,这会延迟加载媒体库。请试试这个,看看是否有帮助!
    【解决方案3】:

    在 .NET Framework 4.7.1 中遇到了这个问题,但是它不会引发异常并且在 .NET Core 2.0 中可以正常工作

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

    var recognizer = factory.CreateSpeechRecognizer();
    

    {"类型初始化器 'Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE' 抛出异常。"}

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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

      • 此设置 x64 或 x32(或除 AnyCPU 之外的任何设置)在 VS 2019 中不存在。还有其他方法吗?
      【解决方案5】:

      这个 dll 真可惜。我失去了 1 小时的生命。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-24
        • 1970-01-01
        • 2017-09-05
        相关资源
        最近更新 更多