Reputation: 187
I am trying to get Azure Speech Synthesis SDK / API to work in a Python container.
Just trying the quickstart in a Python container CLI will get the error message:
Speech synthesis canceled: CancellationReason.Error
Error details: USP error: timeout waiting for the first audio chunk
Did you set the speech resource key and region values?
Yes, the resource key and region values are correct. If I run the quickstart in the localhost CLI, it works. But if I run the quickstart in the container CLI, I get the above error message.
I know there is an OpenSSL limitation so I tried with both Ubuntu 22 (and installed OpenSSL 1.1.1.1) and Ubuntu 20, but both have the same problem. Both works in localhost CLI but not in container CLI.
Is it a container port problem or the Azure SDK / API problem?
I am running on Ubuntu 20 virtualbox client and containers using docker compose. I have included the compose, dockerfile, requirements.txt below:
Docker Compose:
version: "3.8"
services:
# Define our indimyual services
myapp:
build: .
container_name: app
environment:
- PYTHONUNBUFFERED=1
- PYTHONIOENCODING=UTF-8
expose:
- 8888
networks:
- my-network
myserver:
build: ./nginx
container_name: myserver
ports:
- "80:80"
- "443:443"
- ./log/nginx:/var/log/nginx
- ./nginx:/etc/nginx/conf.d
networks:
- my-network
networks:
my-network:
driver: bridge
Dockerfile
# Use the Python3.10 container image
FROM python:3.8.10
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . .
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off
RUN apt update && apt install -y build-essential gcc ffmpeg libsm6 libxext6 wget nano unzip gdebi -y \
&& pip install --upgrade pip \
&& pip install -r requirements.txt
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# set display port to avoid crash
ENV DISPLAY=:99
# Create a uwsgi log directory and files
RUN mkdir /var/log/uwsgi
RUN touch /var/log/uwsgi/uwsgi_access.log
RUN touch /var/log/uwsgi/uwsgi_error.log
# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
Requirements.txt
-i https://pypi.python.org/simple
uwsgi==2.0.22
werkzeug==2.3.6; python_version >= '3.8'
azure-ai-textanalytics==5.2.0
azure-cognitiveservices-speech==1.31.0
azure-common==1.1.28
azure-core==1.28.0; python_version >= '3.7'
flask==2.3.2
jinja2==3.1.2; python_version >= '3.7'
requests==2.31.0; python_version >= '3.7'
uwsgi==2.0.22
nginx.conf
server {
listen 80;
listen 443;
server_name localhost;
index index.php index.html index.htm index.nginx-debian.html;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout 300;
}
}
Upvotes: 0
Views: 519
Reputation: 400
You need to install the additional dependencies for Linux:
# Installing Azure Speech SDK requirements
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev ca-certificates libasound2 wget
and also the python dependencies:
# requirements.txt
azure-cognitiveservices-speech==1.38.0
For reference, I have the following image as base - which is Debian based: mcr.microsoft.com/mirror/docker/library/python:3.11-slim
Upvotes: 0