为语音 SDK 配置 RHEL/CentOS 7Configure RHEL/CentOS 7 for Speech SDK

语音 SDK 1.10.0 及更高版本正式支持 Red Hat Enterprise Linux (RHEL) 8 x64 和 CentOS 8 x64。Red Hat Enterprise Linux (RHEL) 8 x64 and CentOS 8 x64 are officially supported by the Speech SDK version 1.10.0 and later. 也可以在 RHEL/CentOS 7 x64 上使用语音 SDK,但这需要更新你的系统上的 C++ 编译器(用于 C++ 开发)和共享的 C++ 运行时库。It is also possible to use the Speech SDK on RHEL/CentOS 7 x64, but this requires updating the C++ compiler (for C++ development) and the shared C++ runtime library on your system.

若要检查 C++ 编译器版本,请运行:To check the C++ compiler version, run:

g++ --version

如果安装了编译器,则输出应如下所示:If the compiler is installed, the output should look like this:

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

此消息告诉你已安装了 GCC 主版本 4。This message lets you know that GCC major version 4 is installed. 此版本并不完全支持语音 SDK 使用的 C++ 11 标准。This version doesn't have full support for the C++ 11 standard, which the Speech SDK uses. 尝试使用此 GCC 版本和语音 SDK 头编译 C++ 程序会导致编译错误。Trying to compile a C++ program with this GCC version and the Speech SDK headers will result in compilation errors.

还必须检查共享的 C++ 运行时库 (libstdc++) 的版本。It's also important to check the version of the shared C++ runtime library (libstdc++). 大多数语音 SDK 都作为原生 C++ 库实现,这意味着它依赖于 libstdc++,不管应用程序是使用哪种语言开发的。Most of the Speech SDK is implemented as native C++ libraries, meaning it depends on libstdc++ regardless of the language you use to develop applications.

若要查找 libstdc++ 在系统上的位置,请运行:To find the location of libstdc++ on your system, run:

ldconfig -p | grep libstdc++

vanilla RHEL/CentOS 7 (x64) 上的输出为:The output on vanilla RHEL/CentOS 7 (x64) is:

libstdc++.so.6 (libc6,x86-64) => /lib64/libstdc++.so.6

根据此消息,你需要使用以下命令检查版本定义:Based on this message, you'll want to check the version definitions with this command:

strings /lib64/libstdc++.so.6 | egrep "GLIBCXX_|CXXABI_"

输出应该是:The output should be:

...
GLIBCXX_3.4.19
...
CXXABI_1.3.7
...

语音 SDK 需要 CXXABI_1.3.9GLIBCXX_3.4.21The Speech SDK requires CXXABI_1.3.9 and GLIBCXX_3.4.21. 可以通过对 Linux 包中的语音 SDK 库运行 ldd libMicrosoft.CognitiveServices.Speech.core.so 来查找此信息。You can find this information by running ldd libMicrosoft.CognitiveServices.Speech.core.so on the Speech SDK libraries from the Linux package.

备注

建议在系统上安装的 GCC 版本至少为 5.4.0,它具有匹配的运行时库。It is recommended that the version of GCC installed on the system is at least 5.4.0, with matching runtime libraries.

示例Example

下面的示例命令集展示了如何配置 RHEL/CentOS 7 x64 以使用语音 SDK 1.10.0 或更高版本进行开发(C++、C#、Java、Python):This is a sample command set that illustrates how to configure RHEL/CentOS 7 x64 for development (C++, C#, Java, Python) with the Speech SDK 1.10.0 or later:

1.常规安装1. General setup

首先安装所有常规依赖项:First install all general dependencies:

# Only run ONE of the following two commands
# - for CentOS 7:
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
# - for RHEL 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 python3
sudo yum install -y gstreamer1 gstreamer1-plugins-base gstreamer1-plugins-good gstreamer1-plugins-bad-free gstreamer1-plugins-ugly-free

2.C/C++ 编译器和运行时库2. C/C++ compiler and runtime libraries

使用此命令安装必备组件包:Install the prerequisite packages with this command:

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

备注

libmpc-devel 包在 RHEL 7.8 更新中已弃用。The libmpc-devel package has been deprecated in the RHEL 7.8 update. 如果上述命令的输出包含一条消息,If the output of the previous command includes a message

No package libmpc-devel available.

则需从原始源安装所需的文件。then the necessary files need to be installed from original sources. 运行以下命令:Run the following commands:

curl https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz -O
tar zxf mpc-1.1.0.tar.gz
mkdir mpc-1.1.0-build && cd mpc-1.1.0-build
../mpc-1.1.0/configure --prefix=/usr/local --libdir=/usr/local/lib64
make -j$(nproc)
sudo make install-strip

接下来,更新编译器和运行时库:Next update the compiler and runtime libraries:

# Build GCC 5.4.0 and runtimes and install them under /usr/local
curl https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2 -O
tar jxf gcc-5.4.0.tar.bz2
mkdir gcc-5.4.0-build && cd gcc-5.4.0-build
../gcc-5.4.0/configure --enable-languages=c,c++ --disable-bootstrap --disable-multilib --prefix=/usr/local
make -j$(nproc)
sudo make install-strip

如果需要将更新的编译器和库部署在多台计算机上,则只需将它们从 /usr/local 下复制到其他计算机上。If the updated compiler and libraries need to be deployed on several machines, you can simply copy them from under /usr/local to other machines. 如果只需要运行时库,则 /usr/local/lib64 中的文件已足够。If only the runtime libraries are needed then the files in /usr/local/lib64 will be enough.

3.环境设置3. Environment settings

运行以下命令来完成配置:Run the following commands to complete the configuration:

# Set SSL cert file location
# (this is required for any development/testing with Speech SDK)
export SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt

# 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-1.10.0/lib/x64:$LD_LIBRARY_PATH

# For Python: install the Speech SDK module
python3 -m pip install azure-cognitiveservices-speech --user

后续步骤Next steps