docker Runtime error: Failed to initialize platform (azure-c-shared). Error: 2153

503 Views Asked by At

I wrote a text to speech app using "azure.cognitiveservices.speech" , then based on this I build a docker image and run app as a container. It did work in my local, but run the app as a container failed. The error seems happen at "speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)".

this is the error info:

RuntimeError: Exception with error code: 
[CALL STACK BEGIN] /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1f5298) [0xffff9a645298] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fed3c) [0xffff9a64ed3c] 
/lib/aarch64-linux-gnu/libc.so.6(+0x83dc8) [0xffffb3bb3dc8] /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ffcb4) [0xffff9a64fcb4] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1c21f4) [0xffff9a6121f4] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1bc574) [0xffff9a60c574] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fbc64) [0xffff9a64bc64] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1d5744) [0xffff9a625744] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1cf534) [0xffff9a61f534] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xda940) [0xffff9a52a940] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fbc64) [0xffff9a64bc64] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1c8448) [0xffff9a618448] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x2177a4) [0xffff9a6677a4] 
/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(synthesizer_create_speech_synthesizer_from_config+0x10c) [0xffff9a4fd4b0] 
/lib/aarch64-linux-gnu/libffi.so.8(+0x63e0) [0xffffb20663e0] 
/lib/aarch64-linux-gnu/libffi.so.8(+0x5b24) [0xffffb2065b24] 
/usr/local/lib/python3.9/lib-dynload/_ctypes.cpython-39-aarch64-linux-gnu.so(+0xf058) [0xffffb209f058] 
[CALL STACK END] 
Runtime error: Failed to initialize platform (azure-c-shared). Error: 2153
Traceback:
File "/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
File "/app/myapp.py", line 134, in <module>
    main()
File "/app/myapp.py", line 80, in main
    azure_text_to_speech_file(text, accent)
File "/app/speech_synthesis.py", line 28, in azure_text_to_speech_file
    speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/speech.py", line 2149, in __init__
    _call_hr_fn(fn=_sdk_lib.synthesizer_create_speech_synthesizer_from_config, *[
File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/interop.py", line 62, in _call_hr_fn
    _raise_if_failed(hr)
File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/interop.py", line 55, in _raise_if_failed
    __try_get_error(_spx_handle(hr))
File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/interop.py", line 50, in __try_get_error
    raise RuntimeError(message)

and this is the content of my docker file

# Use a base image with Python and specify the version
FROM python:3.9-slim

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the required packages
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code into the container
COPY . .

# Expose the port your Streamlit app is using
EXPOSE 8501

# Command to run your Streamlit application
CMD ["streamlit", "run", "myapp.py"]

I spent a lot of time to slove this problem, but it still can't work. Is there anyone who can help find the problem and solve it ?I am really appreciate

2

There are 2 best solutions below

1
Suresh Chikkam On

I also got the similar error while using azure.cognitiveservices.speech as speechsdk

enter image description here

Proper install pip install azure-cognitiveservices-speech-sdk

Mostly the above errors occurs due to the

#0 7.558 The conflict is caused by:
#0 7.558     The user requested protobuf==3.19.0
#0 7.558     streamlit 1.24.0 depends on protobuf<5 and >=3.20
#0 7.558
#0 7.558 To fix this you could try to:
#0 7.558 1. loosen the range of package versions you've specified
#0 7.558 2. remove package versions to allow pip attempt to solve the dependency conflict

Here I updated my requirement.txt file.

streamlit==1.24.0
azure-cognitiveservices-speech==1.20.0
altair==4.1.0
blinker>=1.0.0
pympler>=0.9
numpy>=1
python-dateutil>=2

Here is my Dockerfile:

# Use a base image with Python and specify the version
FROM python:3.9-slim

# Update the protobuf library to a compatible version
RUN pip install --no-cache-dir protobuf==3.19.0

ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the required packages
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code into the container
COPY . .

# Expose the port your Streamlit app is using
EXPOSE 8501

# Command to run your Streamlit application
CMD ["streamlit", "run", "myapp.py"]

Here I dockerized my application and Iam able see my application in my Docker container.

enter image description here

Iam able run the application from the container using docker run -p 8501:8501 text-to-speech-app

enter image description here

Output:

enter image description here

0
Canada Masakatz On

I had the same problem with the exception below.

RuntimeError: Exception with an error code: 0x38(SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)

So, I added apt-get install libasound2 and fixed it.

Here is my Dockerfile:

FROM python:3.8.10

RUN apt-get update && \
    apt-get install -y \
    libasound2

WORKDIR /app

ADD . /app

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 80

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--reload"]

I found the solution in the following thread.

Azure Speech to text 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)