I need to convert speech from a wav file into text. So I downloaded the sample C# code project from the Quickstart: Recognize speech using Speech service C# SDK page, and followed the instructions on the page.
It works in Windows 10, but I need the project to work on Windows Servers 2012 R2 and it doesn't work on Windows Servers 2012 R2.
When I run it on Windows Servers 2012 R2, I press the 3 key for the 3. Speech recognition with file input option. But when it tries to execute the following code (with valid subscription and region values)
var factory = SpeechFactory.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
The following exception is thrown:
System.TypeInitializationException occurred HResult=0x80131534 Message=The type initializer for 'Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE' threw an exception. Source=Microsoft.CognitiveServices.Speech.csharp StackTrace: at Microsoft.CognitiveServices.Speech.Internal.carbon_csharpPINVOKE.SpeechFactory_FromSubscription(String jarg1, String jarg2) at Microsoft.CognitiveServices.Speech.Internal.SpeechFactory.FromSubscription(String subscription, String region) 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
Inner Exception 1: TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
Inner Exception 2: DllNotFoundException: Unable to load DLL 'Microsoft.CognitiveServices.Speech.csharp.bindings.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I think the Microsoft.CognitiveServices.Speech.csharp.bindings.dll doesn't like running on Windows Server 2012 R2, as it exists in the bin folder (and isn't missing) and works on Windows 10. I wrote the following code in a little Hello World console project and it threw the same exception running on 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}");
}
}
And I've tried running as Administrator in case it was a permission thing. But that didn't do anything.
Can someone please help me \ show me what I need to do to run the Speech service sample on Windows Server 2012 R2?
Ran into this issue with .NET Framework 4.7.1, however it does not throw an exception and works in .NET Core 2.0
Got this error in .NET when the following line is executed
The exact same code in .NET Core 2.0 creates the factory. Also made sure to install the latest Visual C++ Redistributables for 2017
Check your platform settings for your project in Build > Configuration Manager.
It must be set to x64 or x86, not to AnyCpu.
Currently the SDK has a hard dependency on the Windows Media Foundation. Do you have the following dlls on your server image: Ksuser.dll, Mf.dll, Mfcore.dll, Mfplat.dll, Mfreadwrite.dll?
Installing the latest Microsoft Visual C++ Redistributable for Visual Studio 2017 should fix it, see https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads.
(We'll update the docs as soon as possible)