Azure Text-to Speech Error Code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) when using Python 3.10 on Wep App Service

Jared Rice 30 Reputation points
2023-02-26T19:48:36.7366667+00:00

I followed these 2 guides and everything works fine on my local windows 10 machine using python 3.10., but when I deploy my code using VS Code to my linux basic web app service, running python 3.10, I receive the following error.

Guides:

https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstarts/setup-platform?tabs=linux%2Cubuntu%2Cdotnet%2Cjre%2Cmaven%2Cnodejs%2Cmac%2Cpypi&pivots=programming-language-python

and
https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=linux%2Cterminal&pivots=programming-language-python

Troubleshooting:

https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/troubleshooting?tabs=powershell#spxerr_audio_sys_library_not_found

Code:

def response_to_speech(response):

    subscription_key = os.getenv("AZURE_SPEECH")
    region = os.getenv("AZURE_REGION")

    speech_config = speechsdk.SpeechConfig(subscription=subscription_key, region=region)
    audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
    speech_config.speech_synthesis_voice_name='en-US-JennyNeural'

    speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

    audio = speech_synthesizer.speak_text_async(response).get()

    return audio

Dependencies:

Python 3.10.9

libasound2 is already the newest version (1.2.4-1.1).
build-essential is already the newest version (12.9).
libssl-dev is already the newest version (1.1.1n-0+deb11u3).
wget is already the newest version (1.21-1+deb11u1).

Requirement already satisfied: azure-cognitiveservices-speech in ./antenv/lib/python3.10/site-packages (1.25.0)

Error:

Exception Value: Exception with error code: 
[CALL STACK BEGIN]
/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x185fa4) [0x7f1b1a187fa4]
/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ee61a) [0x7f1b1a1f061a]
/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(synthesizer_create_speech_synthesizer_from_config+0xf3) [0x7f1b1a09c9d0]
/usr/lib/x86_64-linux-gnu/libffi.so.7(+0x6d1d) [0x7f1b35120d1d]
/usr/lib/x86_64-linux-gnu/libffi.so.7(+0x6289) [0x7f1b35120289]
/opt/python/3.10.9/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x11c19) [0x7f1b35137c19]
/opt/python/3.10.9/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x11493) [0x7f1b35137493]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(PyObject_Call+0xc3) [0x7f1b38e0d333]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x2a4b) [0x7f1b38df148b]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyFunction_Vectorcall+0x78) [0x7f1b38e00218]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(PyObject_Call+0x11a) [0x7f1b38e0d38a]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x2a4b) [0x7f1b38df148b]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyFunction_Vectorcall+0x78) [0x7f1b38e00218]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyObject_FastCallDictTstate+0x16d) [0x7f1b38df82dd]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(+0x15f5e5) [0x7f1b38e095e5]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyObject_MakeTpCall+0x273) [0x7f1b38df9143]
/opt/python/3.10.9/lib/libpython3.10.so.1.0(_PyEval_EvalFrameDefault+0x6079) [0x7f1b38df4ab9]
[CALL STACK END]
Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)

Traceback:


Traceback (most recent call last):
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/tmp/8db182897509f5b/src/views/chat.py", line 85, in as_view
    audio_response = response_to_speech(text_response)
  File "/tmp/8db182897509f5b/src/views/chat.py", line 129, in response_to_speech
    speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/speech.py", line 2147, in __init__
    _call_hr_fn(fn=_sdk_lib.synthesizer_create_speech_synthesizer_from_config, *[
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 62, in _call_hr_fn
    _raise_if_failed(hr)
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 55, in _raise_if_failed
    __try_get_error(_spx_handle(hr))
  File "/tmp/8db182897509f5b/antenv/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 50, in __try_get_error
    raise RuntimeError(message)
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,713 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,755 questions
{count} vote

Accepted answer
  1. romungi-MSFT 45,731 Reputation points Microsoft Employee
    2023-02-27T08:49:40.7133333+00:00

    Jared Rice I think on the remote app service the default audio config needs to be set to an audio file instead of default as in local machine it cannot default to a speaker in this case.

    Try adding the following to update audio_config

        file_name = "outputaudio.wav"
        file_config = speechsdk.audio.AudioOutputConfig(filename=file_name)
        speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=file_config)
    
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jeanine van Rooyen 1 Reputation point
    2023-03-19T20:59:48.27+00:00

    file_name = "outputaudio.wav"your text

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.