快速入门:安装开发环境Quickstart: Setup development environment

选择目标环境Choose your target environment

Important

需要语音 SDK 版本 1.11.0 或更高版本。Speech SDK version 1.11.0 or later is required.

本指南介绍如何安装用于 .NET Framework (Windows) 的语音 SDKThis guide shows how to install the Speech SDK for .NET Framework (Windows). 如果只是需要包名称以便自行开始,请在 NuGet 控制台中运行 Install-Package Microsoft.CognitiveServices.SpeechIf you just want the package name to get started on your own, run Install-Package Microsoft.CognitiveServices.Speech in the NuGet console.

Important

下载任何 Azure 认知服务语音 SDK,即表示你已确认接受其许可条款。By downloading any of the Azure Cognitive Services Speech SDKs, you acknowledge its license. 有关详细信息,请参阅:For more information, see:

先决条件Prerequisites

本快速入门需要:This quickstart requires:

创建 Visual Studio 项目并安装语音 SDKCreate a Visual Studio project and install the Speech SDK

需安装语音 SDK NuGet 包,以便在代码中引用它。You'll need to install the Speech SDK NuGet package so you can reference it in your code. 为此,可能首先需要创建 helloworld 项目。To do that, you may first need to create a helloworld project. 如果已经有一个可以使用“.NET 桌面开发”工作负荷的项目,则可使用该项目并跳到使用 NuGet 包管理器安装语音 SDKIf you already have a project with the .NET desktop development workload available, you can use that project and skip to Use NuGet Package Manager to install the Speech SDK.

创建 helloworld 项目Create helloworld project

  1. 打开 Visual Studio 2019。Open Visual Studio 2019.

  2. 在“开始”窗口中,选择“创建新项目”。In the Start window, select Create a new project.

  3. 在“创建新项目”窗口中,选择“控制台应用(.NET Framework)”,然后选择“下一步”。 In the Create a new project window, choose Console App (.NET Framework), and then select Next.

  4. 在“配置新项目”窗口中的“项目名称”内输入 helloworld,在“位置”中选择或创建目录路径,然后选择“创建”。 In the Configure your new project window, enter helloworld in Project name, choose or create the directory path in Location, and then select Create.

  5. 在 Visual Studio 菜单栏中,选择“工具” > “获取工具和功能”打开 Visual Studio 安装程序并显示“修改”对话框。 From the Visual Studio menu bar, select Tools > Get Tools and Features, which opens Visual Studio Installer and displays the Modifying dialog box.

  6. 检查“.NET 桌面开发”工作负荷是否可用。Check whether the .NET desktop development workload is available. 如果尚未安装该工作负荷,请选中它旁边的复选框,然后选择“修改”以启动安装。If the workload hasn't been installed, select the check box next to it, and then select Modify to start the installation. 下载和安装过程可能需要几分钟。It may take a few minutes to download and install.

    如果已选中“.NET 桌面开发”旁边的复选框,请选择“关闭”退出对话框。 If the check box next to .NET desktop development is already selected, select Close to exit the dialog box.

    启用 .NET 桌面开发

  7. 关闭 Visual Studio 安装程序。Close Visual Studio Installer.

使用 NuGet 包管理器安装语音 SDKUse NuGet Package Manager to install the Speech SDK

  1. 在解决方案资源管理器中右键单击“helloworld”项目,然后选择“管理 NuGet 包”显示 NuGet 包管理器。 In the Solution Explorer, right-click the helloworld project, and then select Manage NuGet Packages to show the NuGet Package Manager.

    NuGet 包管理器

  2. 在右上角找到“包源”下拉框,确保选择了 nuget.orgIn the upper-right corner, find the Package Source drop-down box, and make sure that nuget.org is selected.

  3. 在左上角,选择“浏览”。In the upper-left corner, select Browse.

  4. 在搜索框中,键入 Microsoft.CognitiveServices.Speech 并按 EnterIn the search box, type Microsoft.CognitiveServices.Speech and select Enter.

  5. 在搜索结果中选择“Microsoft.CognitiveServices.Speech”包,然后选择“安装”以安装最新稳定版本。 From the search results, select the Microsoft.CognitiveServices.Speech package, and then select Install to install the latest stable version.

    安装 Microsoft.CognitiveServices.Speech NuGet 包

  6. 接受所有协议和许可证,开始安装。Accept all agreements and licenses to start the installation.

    安装此包后,“包管理器控制台”窗口中将显示一条确认消息。After the package is installed, a confirmation appears in the Package Manager Console window.

选择目标体系结构Choose target architecture

若要生成并运行控制台应用程序,请创建与计算机体系结构匹配的平台配置。To build and run the console application, create a platform configuration matching your computer's architecture.

  1. 在菜单栏中,选择“生成” > “配置管理器” 。From the menu bar, select Build > Configuration Manager. 此时将显示“配置管理器”对话框。The Configuration Manager dialog box appears.

    “配置管理器”对话框

  2. 在“活动解决方案平台”下拉框中,选择“新建” 。In the Active solution platform drop-down box, select New. 此时将显示“新建解决方案平台”对话框。The New Solution Platform dialog box appears.

  3. 在“键入或选择新平台”下拉框中:In the Type or select the new platform drop-down box:

    • 如果运行的是 64 位 Windows,请选择 x64If you're running 64-bit Windows, select x64.
    • 如果运行的是 32 位 Windows,请选择 x86If you're running 32-bit Windows, select x86.
  4. 选择“确定”,然后选择“关闭”。 Select OK and then Close.

后续步骤Next steps

选择目标环境Choose your target environment

本指南介绍如何安装用于 Linux 的语音 SDKThis guide shows how to install the Speech SDK for Linux

Important

下载任何 Azure 认知服务语音 SDK,即表示你已确认接受其许可条款。By downloading any of the Azure Cognitive Services Speech SDKs, you acknowledge its license. 有关详细信息,请参阅:For more information, see:

系统要求System requirements

Linux(Ubuntu 16.04、Ubuntu 18.04、Debian 9、RHEL 8、CentOS 8)Linux (Ubuntu 16.04, Ubuntu 18.04, Debian 9, RHEL 8, CentOS 8)

先决条件Prerequisites

若要完成本快速入门,你需要:To complete this quickstart, you'll need:

  • Visual Studio 2019Visual Studio 2019

  • 需要语音 SDK 版本 1.10.0 或更高版本。Speech SDK version 1.10.0 or later is required.

  • 支持的 Linux 平台会要求安装某些库(要求安装 libssl 以获取安全套接字层支持;要求安装 libasound2 以获取声音支持)。Supported Linux platforms will require certain libraries installed (libssl for secure sockets layer support and libasound2 for sound support). 请参阅下面的发行版,了解安装这些库的正确版本所需的命令。Refer to your distribution below for the commands needed to install the correct versions of these libraries.

    • 在 Ubuntu 上:On Ubuntu:

      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.0 libasound2 wget
      
    • 在 Debian 9 上:On Debian 9:

      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.2 libasound2 wget
      
    • 在 RHEL/CentOS 8 上:On RHEL/CentOS 8:

      sudo yum update
      sudo yum groupinstall "Development tools"
      sudo yum install alsa-lib openssl wget
      

Note

在 RHEL/CentOS 8 上,按照如何配置 OpenSSL for Linux 上的说明进行操作。On RHEL/CentOS 8, follow the instructions on how to configure OpenSSL for Linux.

安装语音 SDKInstall Speech SDK

适用于 Linux 的语音 SDK 可用于构建 64 位和 32 位应用程序。The Speech SDK for Linux can be used to build both 64-bit and 32-bit applications. 可以从 https://aka.ms/csspeech/linuxbinary 以 tar 文件格式下载必需的库和头文件。The required libraries and header files can be downloaded as a tar file from https://aka.ms/csspeech/linuxbinary.

下载并安装 SDK,如下所示:Download and install the SDK as follows:

  1. 选择应将语音 SDK 文件提取到的目录,然后将 SPEECHSDK_ROOT 环境变量设置为指向该目录。Choose a directory to which the Speech SDK files should be extracted, and set the SPEECHSDK_ROOT environment variable to point to that directory. 使用此变量,在将来的命令中可以轻松引用目录。This variable makes it easy to refer to the directory in future commands. 例如,如果要使用主目录中的 speechsdk 目录,请使用如下所示的命令:For example, if you want to use the directory speechsdk in your home directory, use a command like the following:

    export SPEECHSDK_ROOT="$HOME/speechsdk"
    
  2. 如果该目录尚不存在,请创建该目录。Create the directory if it doesn't exist yet.

    mkdir -p "$SPEECHSDK_ROOT"
    
  3. 下载并提取包含语音 SDK 二进制文件的 .tar.gz 存档:Download and extract the .tar.gz archive containing the Speech SDK binaries:

    wget -O SpeechSDK-Linux.tar.gz https://aka.ms/csspeech/linuxbinary
    tar --strip 1 -xzf SpeechSDK-Linux.tar.gz -C "$SPEECHSDK_ROOT"
    
  4. 验证所提取的程序包的顶级目录的内容:Validate the contents of the top-level directory of the extracted package:

    ls -l "$SPEECHSDK_ROOT"
    

    目录列表应当包含第三方通告和许可证文件,以及一个包含头文件 (.h) 的 include 目录和一个包含库的 lib 目录。The directory listing should contain the third-party notice and license files, as well as an include directory containing header (.h) files and a lib directory containing libraries.

    路径Path 说明Description
    license.md 许可License
    ThirdPartyNotices.md 第三方声明。Third-party notices.
    REDIST.txt 再分发声明。Redistribution notice.
    include C 和 C++ 必需的头文件The required header files for C and C++
    lib/x64 x64 必需的用来链接应用程序的本机库Native library for x64 required to link your application
    lib/x86 x86 必需的用来链接应用程序的本机库Native library for x86 required to link your application

现在可以继续完成下面的后续步骤You can now move on to Next steps below.

后续步骤Next steps

选择目标环境Choose your target environment

本指南介绍如何安装用于 64 位 Java 8 JRE 的语音 SDKThis guide shows how to install the Speech SDK for 64-bit Java 8 JRE. 如果只是需要包名称以便自行开始,那么请知悉在 Maven 中央存储库中未提供 Java SDK。If you just want the package name to get started on your own, the Java SDK is not available in the Maven central repository. 无论是使用 Gradle 还是 pom.xml 依赖项文件,都需要添加指向 https://csspeechstorage.blob.core.windows.net/maven/ 的自定义存储库(请参阅下文了解包名称)。Whether you're using Gradle or a pom.xml dependency file, you need to add a custom repository pointing to https://csspeechstorage.blob.core.windows.net/maven/ (see below for package name).

Note

对于语音设备 SDK 和 Roobo 设备,请参阅语音设备 SDKFor the Speech Devices SDK and the Roobo device, see Speech Devices SDK.

Important

下载任何 Azure 认知服务语音 SDK,即表示你已确认接受其许可条款。By downloading any of the Azure Cognitive Services Speech SDKs, you acknowledge its license. 有关详细信息,请参阅:For more information, see:

支持的操作系统Supported operating systems

  • Java 语音 SDK 包适用于以下操作系统:The Java Speech SDK package is available for these operating systems:
    • Windows:仅 64 位Windows: 64-bit only
    • Mac:macOS X 10.13 或更高版本Mac: macOS X version 10.13 or later
    • Linux:仅 64 位的 Ubuntu 16.04、Ubuntu 18.04、Debian 9、RHEL 8、CentOS 8Linux: 64-bit only on Ubuntu 16.04, Ubuntu 18.04, Debian 9, RHEL 8, CentOS 8

先决条件Prerequisites

  • Java 8JDK 8Java 8 or JDK 8

  • Eclipse Java IDE(要求已安装 Java)Eclipse Java IDE (requires Java already installed)

  • 需要语音 SDK 版本 1.10.0 或更高版本。Speech SDK version 1.10.0 or later is required.

  • 支持的 Linux 平台会要求安装某些库(要求安装 libssl 以获取安全套接字层支持;要求安装 libasound2 以获取声音支持)。Supported Linux platforms will require certain libraries installed (libssl for secure sockets layer support and libasound2 for sound support). 请参阅下面的发行版,了解安装这些库的正确版本所需的命令。Refer to your distribution below for the commands needed to install the correct versions of these libraries.

    • 在 Ubuntu 上,请运行以下命令来安装所需的包:On Ubuntu, run the following commands to install the required packages:

      ```sh
      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.0 libasound2
      ```
      
    • 在 Debian 9 上,请运行以下命令来安装所需的包:On Debian 9, run the following commands to install the required packages:

      ```sh
      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.2 libasound2
      ```
      
    • 在 RHEL/CentOS 8 上,请运行以下命令来安装所需的包:On RHEL/CentOS 8, run the following commands to install the required packages:

      ```sh
      sudo yum update
      sudo yum install alsa-lib java-1.8.0-openjdk-devel openssl
      ```
      

Note

在 RHEL/CentOS 8 上,按照如何配置 OpenSSL for Linux 上的说明进行操作。On RHEL/CentOS 8, follow the instructions on how to configure OpenSSL for Linux.

创建 Eclipse 项目并安装语音 SDKCreate an Eclipse project and install the Speech SDK

  1. 启动 Eclipse。Start Eclipse.

  2. 在 Eclipse Launcher 中,在“工作区”字段中输入某个新工作区目录的名称。 In the Eclipse Launcher, in the Workspace field, enter the name of a new workspace directory. 然后选择“启动”。 Then select Launch.

    Eclipse Launcher 的屏幕截图

  3. 片刻之后,Eclipse IDE 的主窗口将会显示。In a moment, the main window of the Eclipse IDE appears. 关闭欢迎屏幕(如果存在)。Close the Welcome screen if one is present.

  4. 从 Eclipse 菜单栏上,通过选择“文件” “新建” “项目”创建一个新项目。 > > From the Eclipse menu bar, create a new project by choosing File > New > Project.

  5. 将显示“新建项目”对话框 。The New Project dialog box appears. 选择“Java 项目” ,然后选择“下一步” 。Select Java Project, and select Next.

    “新建项目”对话框的屏幕截图,其中突出显示了 Java 项目

  6. 此时将启动“新建 Java 项目”向导 。The New Java Project wizard starts. 在“项目名称” 字段中,输入 quickstart,然后选择 JavaSE 1.8 作为执行环境。In the Project name field, enter quickstart, and choose JavaSE-1.8 as the execution environment. 选择“完成” 。Select Finish.

    “新建 Java 项目”向导的屏幕截图

  7. 如果出现了“打开关联的透视图?”窗口,请选择“打开透视图”。 If the Open Associated Perspective? window appears, select Open Perspective.

  8. 包资源管理器中,右键单击 quickstart 项目。In the Package explorer, right-click the quickstart project. 从上下文菜单中选择“配置” “转换为 Maven 项目”。 > Choose Configure > Convert to Maven Project from the context menu.

    包资源管理器的屏幕截图

  9. 此时将显示“新建 POM”窗口。 The Create new POM window appears. 在“组 ID” 字段中输入 com.microsoft.cognitiveservices.speech.samples,然后在“项目 ID” 字段中输入 quickstartIn the Group Id field, enter com.microsoft.cognitiveservices.speech.samples, and in the Artifact Id field, enter quickstart. 然后选择“完成” 。Then select Finish.

    “新建 POM”窗口的屏幕截图

  10. 打开 pom.xml 文件并对其进行编辑。Open the pom.xml file and edit it.

    • 在文件末尾,在结束标记 </project> 前面,创建一个 repositories 元素,使其中包含对语音 SDK 的 Maven 存储库的引用,如下所示:At the end of the file, before the closing tag </project>, create a repositories element with a reference to the Maven repository for the Speech SDK, as shown here:
    <repositories>
      <repository>
        <id>maven-cognitiveservices-speech</id>
        <name>Microsoft Cognitive Services Speech Maven Repository</name>
        <url>https://csspeechstorage.blob.core.windows.net/maven/</url>
      </repository>
    </repositories>
    
    • 此外,还添加一个 dependencies 元素(使用语音 SDK 版本 1.11.0 作为依赖项):Also add a dependencies element, with the Speech SDK version 1.11.0 as a dependency:
    <dependencies>
      <dependency>
        <groupId>com.microsoft.cognitiveservices.speech</groupId>
        <artifactId>client-sdk</artifactId>
        <version>1.7.0</version>
      </dependency>
    </dependencies>
    
    • 保存更改。Save the changes.

后续步骤Next steps

本指南介绍如何安装用于 Python 的语音 SDKThis guide shows how to install the Speech SDK for Python. 如果只是需要包名称以便自行开始,请运行 pip install azure-cognitiveservices-speechIf you just want the package name to get started on your own, run pip install azure-cognitiveservices-speech.

Important

下载任何 Azure 认知服务语音 SDK,即表示你已确认接受其许可条款。By downloading any of the Azure Cognitive Services Speech SDKs, you acknowledge its license. 有关详细信息,请参阅:For more information, see:

支持的操作系统Supported operating systems

  • Python 语音 SDK 包适用于以下操作系统:The Python Speech SDK package is available for these operating systems:
    • Windows:x64 和 x86Windows: x64 and x86
    • Mac:macOS X 10.12 或更高版本Mac: macOS X version 10.12 or later
    • Linux:基于 x64 的 Ubuntu 16.04/18.04、Debian 9、RHEL 7/8、CentOS 7/8Linux: Ubuntu 16.04/18.04, Debian 9, RHEL 7/8, CentOS 7/8 on x64

先决条件Prerequisites

  • 需要语音 SDK 版本 1.11.0 或更高版本。Speech SDK version 1.11.0 or later is required.

  • 支持的 Linux 平台会要求安装某些库(要求安装 libssl 以获取安全套接字层支持;要求安装 libasound2 以获取声音支持)。Supported Linux platforms will require certain libraries installed (libssl for secure sockets layer support and libasound2 for sound support). 请参阅下面的发行版,了解安装这些库的正确版本所需的命令。Refer to your distribution below for the commands needed to install the correct versions of these libraries.

    • 在 Ubuntu 上,请运行以下命令来安装所需的包:On Ubuntu, run the following commands to install the required packages:

      ```sh
      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.0 libasound2
      ```
      
    • 在 Debian 9 上,请运行以下命令来安装所需的包:On Debian 9, run the following commands to install the required packages:

      ```sh
      sudo apt-get update
      sudo apt-get install build-essential libssl1.0.2 libasound2
      ```
      
    • 在 RHEL/CentOS 8 上,请运行以下命令来安装所需的包:On RHEL/CentOS 8, run the following commands to install the required packages:

      ```sh
      sudo yum update
      sudo yum install alsa-lib openssl python3
      ```
      

Note

在 RHEL/CentOS 8 上,按照如何配置 OpenSSL for Linux 上的说明进行操作。On RHEL/CentOS 8, follow the instructions on how to configure OpenSSL for Linux.

  • 在 Windows 上,需要安装适用于平台的 Microsoft Visual C++ Redistributable for Visual Studio 2019On Windows, you need the Microsoft Visual C++ Redistributable for Visual Studio 2019 for your platform. 请注意,首次安装它时,可能需要重启 Windows 才能继续使用本指南。Note that installing this for the first time may require you to restart Windows before continuing with this guide.
  • 最后,需要 Python 3.5 到 3.8And finally, you'll need Python 3.5 to 3.8. 若要检查安装,请打开命令提示符并键入命令 python --version,然后检查结果。To check your installation, open a command prompt and type the command python --version and check the result. 如果安装正确,将会收到“Python 3.5.1”或类似的响应。If it's installed properly, you'll get a response "Python 3.5.1" or similar.

从 PyPI 安装语音 SDKInstall the Speech SDK from PyPI

如果使用自己的环境或生成工具,请运行以下命令,从 PyPI 安装语音 SDK。If you're using your own environment or build tools, run the following command to install the Speech SDK from PyPI. 对于 Visual Studio Code 的用户,请跳到下一子部分以按照指导安装。For users of Visual Studio Code, skip to the next sub-section for guided installation.

pip install azure-cognitiveservices-speech

如果在 macOS 上操作,可能需要运行以下命令才能让上述 pip 命令正常运行:If you are on macOS, you may need to run the following command to get the pip command above to work:

python3 -m pip install --upgrade pip

成功使用 pip 安装 azure-cognitiveservices-speech 后,可以通过将命名空间导入 Python 项目来使用语音 SDK。Once you've successfully used pip to install azure-cognitiveservices-speech, you can use the Speech SDK by importing the namespace into your Python projects.

import azure.cognitiveservices.speech as speechsdk

使用 Visual Studio Code 安装语音 SDKInstall the Speech SDK using Visual Studio Code

  1. 下载并安装适用于你的平台的最新受支持 Python 版本(3.5 到 3.8)。Download and install the latest supported version of Python for your platform, 3.5 to 3.8.

    • 在安装过程中,Windows 用户必须选择“将 Python 添加到 PATH”。Windows users make sure to select "Add Python to your PATH" during the installation process.
  2. 下载并安装 Visual Studio CodeDownload and install Visual Studio Code.

  3. 打开 Visual Studio Code 并安装 Python 扩展。Open Visual Studio Code and install the Python extension. 在菜单中选择“文件”**** > ****“首选项” > ****“扩展”。Select File > Preferences > Extensions from the menu. 搜索 Python 并单击“安装”。****Search for Python and click Install.

    安装 Python 扩展

  4. 同样在 Visual Studio Code 中,通过集成式命令行安装语音 SDK Python 包:Also from within Visual Studio Code, install the Speech SDK Python package from the integrated command line:

    1. 打开终端(在下拉菜单中选择“终端” > “新终端”)**** ****Open a terminal (from the drop-down menus, Terminal > New Terminal)
    2. 在打开的终端中输入命令 python -m pip install azure-cognitiveservices-speechIn the terminal that opens, enter the command python -m pip install azure-cognitiveservices-speech

如果你不熟悉 Visual Studio Code,请参阅更详细的 Visual Studio Code 文档If you are new to Visual Studio Code, refer to the more extensive Visual Studio Code Documentation. 有关 Visual Studio Code 和 Python 的详细信息,请参阅 Visual Studio Code Python 教程For more information about Visual Studio Code and Python, see Visual Studio Code Python tutorial.

支持和更新Support and updates

语音 SDK Python 包的更新将通过 PyPI 分发,发行说明中会发布相关通告。Updates to the Speech SDK Python package are distributed via PyPI and announced in the Release notes. 如果有新版本可用,可以使用 pip install --upgrade azure-cognitiveservices-speech 命令进行更新。If a new version is available, you can update to it with the command pip install --upgrade azure-cognitiveservices-speech. 通过查看 azure.cognitiveservices.speech.__version__ 变量来检查当前安装的版本。Check which version is currently installed by inspecting the azure.cognitiveservices.speech.__version__ variable.

如果遇到问题或者缺少某项功能,请查看支持和帮助选项If you have a problem, or you're missing a feature, see Support and help options.

后续步骤Next steps