'Azure Text to Speech Error: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) when deploying to Azure App Services Linux environment

I adapted the quick start code Python version here for Azure text to speech.
The app runs correctly on my local server. However, when I deploy the app through Visual Studio Code to Azure App Services, I got the error: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND). I found that this error is the same as the posts here and here. The reason seems to be that the Python interpreter used was from Microsoft Store instead of from Python.org. The solution, therefore, seems to be switching from the Microsoft Store version of Python to the Python.org version of python.

However, the solution above seems only work for those apps that run on a local or remote server. Since I am deploying my app to Azure App Services, and the deployment builds everything remote using oryx, I don't know how to switch from Microsoft Store version Python to the Python.org version python remotely. I tried to change the Azure App Services Python version using Powershell, following the instruction from this post, but I was only able to change it from the current version of Python 3.9 to Python 3.8. When trying to change to version 3.10, I got an error message saying Python 3.10 is not supported.

After changing to Python 3.8, a new error was given:

ModuleNotFoundError at /
No module named '_speech_py_impl'

Thanks to @RajkumarMamidiChettu-MT for the instruction in the answer below. I think the solution is at the right direction. However, I got stuck at Step 3: My Azure app resource group is Linux (this seems to be default for Python apps and I can't change it). Therefore my kudu site does not have the UI of Debug Console and I cannot drag and drop my local Python package to the server. I do see that I have SSH and BASH interface. However, I don't know how and where to upload the package with either SSH or Bash. screenshot of my KUDU site Hopefully, someone can point me to the right direction. I feel I am getting so close.



Solution 1:[1]

You can use the custom Python version in Windows App Service by following the below steps:

Step 1: Install preferred version of Python on your local machine:

  • Download installation file from below link :

Ex: https://www.python.org/downloads/release/python-388/

enter image description here

  • Run the python-3.8.8-amd64.exe in my local windows machine?
    enter image description here

  • Make sure check to install pip:

enter image description here

  • Select the target path to install python:

enter image description here

  • Compress the whole Python388 folder to Python38.zip:

enter image description here

  • Inside the zip file, it should contains all the following contents:

enter image description here

Step 2: Upload your Python to Windows App Service:

  • Go to your web app Kudu site https://.scm.azurewebsites.net/DebugConsole
    Under D:\home, drag your Python38.zip file to the Kudu console.
    It will automatically unzip it.

enter image description here

  • You can see the new “Python38” folder being generated.

enter image description here

Step 3: Add the custom Python binary into the PATH environment variable:

  • Create an applicationhost.xdt file in D:\home\site folder:

enter image description here

-Sample applicationhost.xdt file contents:

<?xml version="1.0"?> 
    <configuration xmlns:xdt= http://schemas.microsoft.com/XML-Document-Transform> 
      <system.webServer> 
        <runtime xdt:Transform="InsertIfMissing">
          <environmentVariables xdt:Transform="InsertIfMissing">
            <add name="PATH" value="%HOME%\Python388\;%PATH%" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
          </environmentVariables>
        </runtime> 
      </system.webServer> 
</configuration>
  • Then Restart the Web App. Every time you Restart the web app, the platform will check your D:\home\sites\applicationhost.xdt file, use it to transfer the D:\local\Config\applicationhost.config.

  • The transform logs are all recorded in D:\home\LogFiles\Transform, you can check the timestamp and file name to get the latest log.

enter image description here

  • Check your D:\local\Config\applicationhost.config file, should see Python path being added as the “PATH” environment variables.

enter image description here

  • In the Kudu Powershell console, use “python -V” to check Python version. You should be able to see the customer Python version.

enter image description here

enter image description here

note-

  1. Microsoft has deprecated the Python extensions for App Service on Windows in favor of a direct deployment to App Service on Linux.

  2. If your application can run on the following version of Python, you can use platform provided Python extensions, rather than deploy your own version of Python.

enter image description here

Solution 2:[2]

For what it's worth, I found the Azure Text to Speech Error: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) error in my situation is because the deployment process was looking for the Linux version of Azure-Congnitiveservices-speech library, which ends with .so. However, for whatever reason, those .so library files were not generated when deploying my app to the Azure Linux environment. And the method mentioned in another post Azure Speech to text 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND) of manually pasting .dll (library files in windows) files to the execution path didn't work, because the web app environment is Linux, which is the default environment by Azure App Services for the Python web app. And there is no way to change the web app environment from Linux to Windows if using Azure's preconfigured web app environment to deploy a python app.

I was not able to figure out how to generate .so files for the Azure-Congnitiveservices-Speech pack with the default Linux environment. So I end up creating a custom Docker Windows Server container with Python 3.10, WindowsServer2019 (python:3.10.4-windowsservercore-1809 2022 is not supported at the time of this post), and then deploying it to Azure App Services with the customer docker container. It is working now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2