Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.8k stars 1.83k forks source link

Error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) #1310

Closed zpemberton closed 2 years ago

zpemberton commented 2 years ago

Describe the bug I am running the quickstart.py code sample for Text-To-Speech. I have attempted to run it without any changes, or with the key and region entered and still receive the same errors below.

_impl = synth_type._from_config(speech_config._impl) RuntimeError: Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) [CALL STACK BEGIN]

> pal_string_to_wstring

- synthesizer_create_speech_synthesizer_from_config

- synthesizer_create_speech_synthesizer_from_config

- 00007FFDAC846924 (SymFromAddr() error: Attempt to access invalid address.)

- 00007FFDAC894AA6 (SymFromAddr() error: Attempt to access invalid address.)

- 00007FFDAC895534 (SymFromAddr() error: Attempt to access invalid address.)

- PyLong_AsDouble

- PyEval_EvalFrameDefault

- PyFunction_Vectorcall

- PyEval_EvalFrameDefault

- PyObject_GC_Del

- PyFunction_Vectorcall

- PyType_GenericNew

- PyType_GenericNew

- PyObject_MakeTpCall

- PyEval_EvalFrameDefault

[CALL STACK END]

To Reproduce Steps to reproduce the behavior:

  1. change region and speech key
  2. run quickstart.py and receive error

Expected behavior The next step to show would be to ask me for text input.

Version of the Cognitive Services Speech SDK packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (1.19.0)

Platform, Operating System, and Programming Language

jhakulin commented 2 years ago

@zpemberton Thanks for the report. I checked 1.19.0 and steps based on the quickstart for text to speech on Windows and could not reproduce the issue. I installed Python from https://www.python.org/downloads/release/python-398/. What is the exact version of Python you are using ?

zpemberton commented 2 years ago

@zpemberton Thanks for the report. I checked 1.19.0 and steps based on the quickstart for text to speech on Windows and could not reproduce the issue. I installed Python from https://www.python.org/downloads/release/python-398/. What is the exact version of Python you are using ?

@jhakulin python --version
Python 3.9.8

Code being used

Copyright (c) Microsoft. All rights reserved.

Licensed under the MIT license. See LICENSE.md file in the project root for full license information.

import azure.cognitiveservices.speech as speechsdk

Creates an instance of a speech config with specified subscription key and service region.

Replace with your own subscription key and service region (e.g., "westus").

speech_key, service_region = "xxxxxxxxxxxxxxxxxxxxxxx", "eastus2" speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

Creates a speech synthesizer using the default speaker as audio output.

speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)

Receives a text from console input.

print("Type some text that you want to speak...") text = input()

Synthesizes the received text to speech.

The synthesized speech is expected to be heard on the speaker with this line executed.

result = speech_synthesizer.speak_text_async(text).get()

Checks result.

if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted: print("Speech synthesized to speaker for text [{}]".format(text)) elif result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details print("Speech synthesis canceled: {}".format(cancellation_details.reason)) if cancellation_details.reason == speechsdk.CancellationReason.Error: if cancellation_details.error_details: print("Error details: {}".format(cancellation_details.error_details)) print("Did you update the subscription info?")

jhakulin commented 2 years ago

@zpemberton Could you try to reinstall azure-cognitiveservices-speech using pip and provide pip.log ? pip --log pip.log install azure-cognitiveservices-speech

After installation Speech SDK libraries should be installed probably to C:\Users\\AppData\Local\Programs\Python\Python39\Lib\site-packages\azure\cognitiveservices\speech

Could you check that contains Microsoft.CognitiveServices.Speech.extension.audio.sys.dll ?

ajosic commented 2 years ago

I'm running into the same exception on Windows, trying out the Unity quick start example code with 1.19.0. Unable to new up a SpeechRecognizer:

using (var recognizer = new SpeechRecognizer(config))

ApplicationException: Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail (System.IntPtr hr) (at <5adae604d1ff441081446b32d9e0fb05>:0)

I do have all the .dll files from the .unity package, checked for .extension.audio.sys.dll

Windows ver: 10 Business, 20H2, build# 19042.1237

zpemberton commented 2 years ago

@zpemberton Could you try to reinstall azure-cognitiveservices-speech using pip and provide pip.log ? pip --log pip.log install azure-cognitiveservices-speech

After installation Speech SDK libraries should be installed probably to C:\Users\AppData\Local\Programs\Python\Python39\Lib\site-packages\azure\cognitiveservices\speech

Could you check that contains Microsoft.CognitiveServices.Speech.extension.audio.sys.dll ?

@jhakulin I have uninstalled and reinstalled the package and yes, it does contain the .dll file you mentioned. I'm at a loss to get this working right now.

jhakulin commented 2 years ago

@zpemberton If Microsoft.CognitiveServices.Speech.extension.audio.sys.dll is found then one possible reason is missing Windows audio/media libraries as they are the dependencies for audio.sys library. Does the speaker output work normally in your Windows 10 Enterprise ?

jhakulin commented 2 years ago

@zpemberton, @ajosic Could you please check if anti virus software could be blocking the extension to load? See the issue below: https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/684

If this is the case, we need to find out why that happens.

zpemberton commented 2 years ago

@jhakulin I have solved this issue. I had two python interpreters (one from windows store and one from python.org). I switched the interpreter to the python.org and copied over the azure site packages to that install location. Works perfectly now.

jhakulin commented 2 years ago

@zpemberton That is great and thank you for sharing. We have had similar issues (not finding the dlls with Python) in a past and it is very helpful to get details why problems happened, this will help us in the future. Closing the case. @ajosic In case you still have problems with Unity, please create a new issue for that.

sarang-lvs commented 1 year ago

I am having the exact same error code when using speechsdk. It works perfectly on local but gives this error when deployed on Azure web app with Python deployment.

TasseDeCafe commented 1 year ago

Same, when running this test function on Ubuntu:

`import azure.cognitiveservices.speech as speechsdk import os

def test_generate_audio_azure(text: str): speech_key = os.environ.get("AZURE_SPEECH_API_KEY") speech_region = "eastus" speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=speech_region)

speech_config.set_property(speechsdk.PropertyId.SpeechServiceConnection_SynthOutputFormat, "audio-48khz-192kbitrate-mono-mp3")
speech_config.speech_synthesis_voice_name = "en-US-Guy24kRUS"  # Replace with your preferred voice

output_file = "test_output.mp3"
audio_config = speechsdk.audio.AudioOutputConfig(filename=output_file)
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

result = synthesizer.speak_text_async(text).get()
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print(f"Text to speech successful. Generated audio file: {output_file}")
elif result.reason == speechsdk.ResultReason.Canceled:
    print(f"Failed to synthesize text to speech: {result.cancellation_details.reason}")
    if result.cancellation_details.reason == speechsdk.CancellationReason.Error:
        print(f"Error details: {result.cancellation_details.error_details}")
else:
    print("Unknown error during speech synthesis")

if name == "main": test_generate_audio_azure("This is a test")`

I get the following error:

Traceback (most recent call last): File "/home/xxxxxx/yyyyyyy/test_azure_speech.py", line 31, in test_generate_audio_azure("This is a test") File "/home/xxxxxx/yyyyyyy/test_azure_speech.py", line 18, in test_generate_audio_azure synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config) File "/home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/speech.py", line 1515, in init self._impl = self._get_impl(impl.SpeechSynthesizer, speech_config, audio_config, auto_detect_source_language_config) File "/home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/speech.py", line 1619, in _get_impl _impl = synth_type._from_config(speech_config._impl, None if audio_config is None else audio_config._impl) RuntimeError: Runtime error: Failed to initialize platform (azure-c-shared) [CALL STACK BEGIN]

/home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1a77ca) [0x7f11f3da77ca] /lib/x86_64-linux-gnu/libc.so.6(+0x95577) [0x7f11f5095577] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1b784f) [0x7f11f3db784f] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1804bb) [0x7f11f3d804bb] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x17f11f) [0x7f11f3d7f11f] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ab762) [0x7f11f3dab762] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1beaf6) [0x7f11f3dbeaf6] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x169a0c) [0x7f11f3d69a0c] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xcfa0d) [0x7f11f3ccfa0d] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ab762) [0x7f11f3dab762] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x161c6f) [0x7f11f3d61c6f] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1c81b9) [0x7f11f3dc81b9] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(synthesizer_create_speech_synthesizer_from_config+0xf3) [0x7f11f3ca5ba2] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/_speech_py_impl.so(+0x8d53e) [0x7f11f448d53e] /home/xxxxxx/yyyyyyy/venv/lib/python3.10/site-packages/azure/cognitiveservices/speech/_speech_py_impl.so(+0xf40b6) [0x7f11f44f40b6] python3(+0x15d798) [0x555e07fbf798] python3(_PyObject_MakeTpCall+0x25b) [0x555e07fb6f5b] [CALL STACK END]

Xiaobonor commented 1 year ago

same

Traceback (most recent call last): File "/home/xiaobo/ChuanhuChatGPT/modules/base_model.py", line 362, in predict chatbot, status_text = self.next_chatbot_at_once( File "/home/xiaobo/ChuanhuChatGPT/modules/base_model.py", line 181, in next_chatbot_at_once ai_reply, total_token_count = self.get_answer_at_once(self.isimg, self.reply_language, self.audio_generation) File "/home/xiaobo/ChuanhuChatGPT/modules/models.py", line 96, in get_answer_at_once File "/home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/speech.py", line 2149, in init _call_hr_fn(fn=_sdk_lib.synthesizer_create_speech_synthesizer_from_config, *[ File "/home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 62, in _call_hr_fn _raise_if_failed(hr) File "/home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 55, in _raise_if_failed try_get_error(_spx_handle(hr)) File "/home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 50, in try_get_error raise RuntimeError(message) RuntimeError: Exception with error code: [CALL STACK BEGIN]

/home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1aed40) [0x7f52691e9d40] /home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1f7d3c) [0x7f5269232d3c] /home/xiao_bo_nor/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(synthesizer_create_speech_synthesizer_from_config+0xf3) [0x7f526910acae] /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c) [0x7f527a3c7dae] /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call+0x22f) [0x7f527a3c771f] /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x11e0a) [0x7f527a5dbe0a] /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0xc2f7) [0x7f527a5d62f7] python3(_PyObject_Call+0x231) [0x607291] python3(_PyEval_EvalFrameDefault+0x2133) [0x593c03] python3() [0x590e86] python3(_PyObject_Call+0xe4) [0x607144] python3(_PyEval_EvalFrameDefault+0x2133) [0x593c03] python3() [0x590e86] python3(_PyObject_FastCallDictTstate+0xca) [0x60e13a] python3() [0x5a1430] python3() [0x5b146e] python3(_PyObject_MakeTpCall+0x3bd) [0x60dfdd] [CALL STACK END]

Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)

TasseDeCafe commented 1 year ago

I solved it like this:

https://github.com/MicrosoftDocs/azure-docs/issues/104791

This is a problem specific to Ubuntu 22. Make sure the native libraries are installed.