How to fix Microsoft Cognitive Speech error "Failed to initialize platform (azure-c-shared)"?
Asked Answered
P

2

8

I am using Microsoft.CognitiveServices.Speech (https://www.nuget.org/packages/Microsoft.CognitiveServices.Speech) in Unity.

In the editor with a Windows target everything works perfectly, but I get an error in a Dedicated Server build for Linux (running on Ubuntu 22.04 LTS).

The error:

ApplicationException: Runtime error: Failed to initialize platform (azure-c-shared). Error: 2153
  at Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail (System.IntPtr hr) [0x0005d] in <439ae8e654bd4287a1d7ffd07bb64d43>:0 
  at Microsoft.CognitiveServices.Speech.SpeechSynthesizer.FromConfig (Microsoft.CognitiveServices.Speech.SpeechConfig speechConfig, Microsoft.CognitiveServices.Speech.Audio.AudioConfig audioConfig) [0x00030] in <439ae8e654bd4287a1d7ffd07bb64d43>:0 
  at Microsoft.CognitiveServices.Speech.SpeechSynthesizer..ctor (Microsoft.CognitiveServices.Speech.SpeechConfig speechConfig, Microsoft.CognitiveServices.Speech.Audio.AudioConfig audioConfig) [0x00000] in <439ae8e654bd4287a1d7ffd07bb64d43>:0 
  at Evo.TTS.TTSClientMicrosoft.ConvertTextToSpeechAsync (Evo.Gender gender, System.String text) [0x0004c] in <dbdd55022f014a4e90cc144f717d0703>:0 
  at Evo.TTS.TTSClient.ConvertTextToSpeechAsync (Evo.Gender gender, System.String text) [0x00073] in <dbdd55022f014a4e90cc144f717d0703>:0 
  at Evo.TTS.VoiceController.TextToAudioData (System.String text) [0x0007c] in <dbdd55022f014a4e90cc144f717d0703>:0 
  at Evo.TTS.VoiceController.CmdSpeak (System.String text) [0x00078] in <dbdd55022f014a4e90cc144f717d0703>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <7fb66c41b6e641fb91b7fd5e48b4c50d>:0 
  at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <46e7a35cb7c643d69d5edabca2b1a316>:0 
  at UnityEngine.UnitySynchronizationContext.Exec () [0x00056] in <46e7a35cb7c643d69d5edabca2b1a316>:0 
  at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00014] in <46e7a35cb7c643d69d5edabca2b1a316>:0 
public async Task<SpeechSynthesisResult> ConvertTextToSpeechAsync(Gender gender, string text)
        {
            var speechConfig = SpeechConfig.FromSubscription("REMOVED_THE_KEY", "eastus");
            // Note: if only language is set, the default voice of that language is chosen.
            speechConfig.SpeechSynthesisLanguage = "en-US"; // For example, "de-DE"
                                                            // The voice setting will overwrite the language setting.
                                                            // The voice setting will not overwrite the voice element in input SSML.
            if (gender == Gender.Female)
            {
                speechConfig.SpeechSynthesisVoiceName = "en-US-AshleyNeural";
            }
            else
            {
                speechConfig.SpeechSynthesisVoiceName = "en-US-DavisNeural";
            }

            using (var synthesizer = new SpeechSynthesizer(speechConfig, null))
            {
                var res = await synthesizer.SpeakTextAsync(text);
                Debug.Log(res.Reason);
                CheckResultForErrors(res);
                return res;
            }
        }
Popup answered 25/6, 2022 at 3:18 Comment(1)
Had the same issue. Fixed it by simply downgrading to Heroku 20 (which uses Ubuntu-20), in place of 22. This comes from the fact that Ubuntu 22 uses OpenSSL 3.0 (in place of libssl1.1) by default. For people on Heroku, there's a help page addressing the issue.Appurtenant
P
6

Fixed by following the steps on https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstarts/setup-platform?pivots=programming-language-csharp&tabs=linux%2Cubuntu%2Cdotnet%2Cjre%2Cmaven%2Cnodejs%2Cmac%2Cpypi. Special native dependencies are required.

Popup answered 25/6, 2022 at 15:59 Comment(1)
The link for libssl on Ubuntu 22.04 wget is brokenGoatsucker
C
2

In my case, I came here because I received the same error from a container.

The .NET 8 images are using libssl 3 now:

https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/debian-version#new-behavior

But the Cognitive Services SDK does not yet support it:

The Speech SDK does not yet support OpenSSL 3.0, which is the default in Ubuntu 22.04 and Debian 12.

Downgrading to a .NET 7 image made it run for me but you could also install libssl 1.1 (linked to in a different answer).

There's a GitHub thread about it here: https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/2048

Classicism answered 1/12, 2023 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.