azure text2speech 在centos系统上进行配置

azure text2speech 在centos系统上进行配置

使用java开发azure的text2speech服务时,在windows本机运行ok,但是打成jar包放到centos7系统上运行时,会出现:java.lang.UnsatisfiedLinkError: 'void com.microsoft.cognitiveservices.speech.SpeechConfig.setTempDirectory(java.lang.String)' - Java CentOS 7,可以参照以下方式解决:

To use the Speech SDK on Red Hat Enterprise Linux (RHEL) 7 x64 and CentOS 7 x64, update the C++ compiler (for C++ development) and the shared C++ runtime library on your system.

Install dependencies

1
2
3
4
5
6
7
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

# Install development tools and libraries
sudo yum update -y
sudo yum groupinstall -y "Development tools"
sudo yum install -y alsa-lib dotnet-sdk-2.1 java-1.8.0-openjdk-devel openssl
sudo yum install -y gstreamer1 gstreamer1-plugins-base gstreamer1-plugins-good gstreamer1-plugins-bad-free gstreamer1-plugins-ugly-free

C/C++ compiler and runtime libraries

Install the prerequisite packages with this command:

1
sudo yum install -y gmp-devel mpfr-devel libmpc-devel

Next update the compiler and runtime libraries:

1
2
3
4
5
6
7
# Build GCC 7.5.0 and runtimes and install them under /usr/local
curl https://ftp.gnu.org/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz -O
tar -xf gcc-7.5.0.tar.gz
mkdir gcc-7.5.0-build && cd gcc-7.5.0-build
../gcc-7.5.0/configure --enable-languages=c,c++ --disable-bootstrap --disable-multilib --prefix=/usr/local
make -j$(nproc)
sudo make install-strip

Environment settings

Run the following commands to complete the configuration:

1
2
3
4
5
6
7
8
9
10
11
12
# Add updated C/C++ runtimes to the library path
# (this is required for any development/testing with Speech SDK)
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
# 只运行上面这一行就行了,可以写到环境变量中
# For C++ development only:
# - add the updated compiler to PATH
# (note, /usr/local/bin should be already first in PATH on vanilla systems)
# - add Speech SDK libraries from the Linux tar package to LD_LIBRARY_PATH
# (note, use the actual path to extracted files!)
export PATH=/usr/local/bin:$PATH
hash -r # reset cached paths in the current shell session just in case
export LD_LIBRARY_PATH=/path/to/extracted/SpeechSDK-Linux-<version>/lib/centos7-x64:$LD_LIBRARY_PATH

参考链接:

java.lang.UnsatisfiedLinkError: ‘void com.microsoft.cognitiveservices.speech.SpeechConfig.setTempDirectory(java.lang.String)’ - Java CentOS 7 · Issue #1461 · Azure-Samples/cognitive-services-speech-sdk (github.com)

How to configure RHEL/CentOS 7 - Speech service - Azure AI services | Microsoft Learn