快速入门:识别来自麦克风的语音Quickstart: Recognize speech from a microphone

重要

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

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK C# 示例You can view or download all Speech SDK C# Samples on GitHub.

选择目标环境Choose your target environment

先决条件Prerequisites

准备工作:Before you get started:

在 Visual Studio 中打开项目Open your project in Visual Studio

第一步是确保在 Visual Studio 中打开项目。The first step is to make sure that you have your project open in Visual Studio.

  1. 启动 Visual Studio 2019。Launch Visual Studio 2019.
  2. 加载项目并打开 Program.cs。Load your project and open Program.cs.

源代码Source code

将 Program.cs 文件的内容替换为以下 C# 代码。Replace the contents of the Program.cs file with the following C# code.

using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;

namespace Speech.Recognition
{
    class Program
    {
        static async Task Main()
        {
            await RecognizeSpeechAsync();

            Console.WriteLine("Please press any key to continue...");
            Console.ReadLine();
        }

        static async Task RecognizeSpeechAsync()
        {
            var config =
                SpeechConfig.FromSubscription(
                    "YourSubscriptionKey",
                    "YourServiceRegion");

            using var recognizer = new SpeechRecognizer(config);
            
            var result = await recognizer.RecognizeOnceAsync();
            switch (result.Reason)
            {
                case ResultReason.RecognizedSpeech:
                    Console.WriteLine($"We recognized: {result.Text}");
                    break;
                case ResultReason.NoMatch:
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                    break;
                case ResultReason.Canceled:
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
    
                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                    break;
            }
        }
    }
}

用语音资源中的实际值替换 YourSubscriptionKey 值和 YourServiceRegion 值。Replace the YourSubscriptionKey and YourServiceRegion values with actual values from the Speech resource.

  • 导航到 Azure 门户,然后打开语音资源Navigate to the Azure portal , and open the Speech resource
  • 在左侧的“密钥”下,有两个可用的订阅密钥 Under the Keys on the left, there are two available subscription keys
    • 使用其中的任一密钥来替换 YourSubscriptionKeyUse either one as the YourSubscriptionKey value replacement
  • 在左侧的“概览” 下,记下该区域并将其映射到区域标识符Under the Overview on the left, note the region and map it to the region identifier
    • 使用区域标识符 来替换 YourServiceRegion 值,例如:使用 "chinaeast2" 来替换“中国东部 2” Use the Region identifier as the YourServiceRegion value replacement, for example: "chinaeast2" for China East 2

代码说明Code explanation

需要语音资源订阅密钥和区域才能创建语音配置对象。The Speech resource subscription key and region are required to create a speech configuration object. 实例化语音识别器对象需要配置对象。The configuration object is needed to instantiate a speech recognizer object.

识别器实例公开了多种用于识别语音的方法。The recognizer instance exposes multiple ways to recognize speech. 在此示例中识别了一次语音。In this example, speech is recognized once. 此功能是告知语音服务,你要发送单个需识别的短语,并且在该短语被识别后会停止识别语音。This functionality lets the Speech service know that you're sending a single phrase for recognition, and that once the phrase is identified to stop recognizing speech. 生成结果后,代码会将识别原因写入控制台。Once the result is yielded, the code will write the recognition reason to the console.

提示

语音 SDK 将默认使用 en-us 作为语言进行识别。若要了解如何选择源语言,请参阅指定语音转文本的源语言The Speech SDK will default to recognizing using en-us for the language, see Specify source language for speech to text for information on choosing the source language.

生成并运行应用Build and run app

现在,可以使用语音服务重新构建应用并测试语音识别功能。Now you're ready to rebuild your app and test the speech recognition functionality using the Speech service.

  1. “编译代码”- 在 Visual Studio 菜单栏中,选择“生成” > “生成解决方案” 。Compile the code - From the menu bar of Visual Studio, choose Build > Build Solution.
  2. 启动应用 - 在菜单栏中,选择“调试” > “开始调试”,或按 F5 Start your app - From the menu bar, choose Debug > Start Debugging or press F5.
  3. 开始识别 - 它会提示你说英语短语。Start recognition - It will prompt you to speak a phrase in English. 语音将发送到语音服务,转录为文本,并在控制台中呈现。Your speech is sent to the Speech service, transcribed as text, and rendered in the console.

后续步骤Next steps

了解语音识别的这些基本知识后,请继续浏览基础知识,了解语音 SDK 中的常见功能和任务。With this base knowledge of speech recognition, continue exploring the basics to learn about common functionality and tasks within the Speech SDK.

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK C++ 示例You can view or download all Speech SDK C++ Samples on GitHub.

选择目标环境Choose your target environment

先决条件Prerequisites

准备工作:Before you get started:

源代码Source code

创建一个名为 helloworld.cpp 的 C++ 源文件,并将以下代码粘贴到其中。Create a C++ source file named helloworld.cpp, and paste the following code into it.

```cpp
#include <iostream> // cin, cout
#include <speechapi_cxx.h>

using namespace std;
using namespace Microsoft::CognitiveServices::Speech;

void recognizeSpeech() {
    // Creates an instance of a speech config with specified subscription key and service region.
    // Replace with your own subscription key and service region (e.g., "chinaeast2").
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");


    // Creates a speech recognizer
    auto recognizer = SpeechRecognizer::FromConfig(config);
    cout << "Say something...\n";

    // Starts speech recognition, and returns after a single utterance is recognized. The end of a
    // single utterance is determined by listening for silence at the end or until a maximum of 15
    // seconds of audio is processed.  The task returns the recognition text as result. 
    // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
    // shot recognition like command or query. 
    // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
    auto result = recognizer->RecognizeOnceAsync().get();

    // Checks result.
    if (result->Reason == ResultReason::RecognizedSpeech) {
        cout << "We recognized: " << result->Text << std::endl;
    }
    else if (result->Reason == ResultReason::NoMatch) {
        cout << "NOMATCH: Speech could not be recognized." << std::endl;
    }
    else if (result->Reason == ResultReason::Canceled) {
        auto cancellation = CancellationDetails::FromResult(result);
        cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;

        if (cancellation->Reason == CancellationReason::Error) {
            cout << "CANCELED: ErrorCode= " << (int)cancellation->ErrorCode << std::endl;
            cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
            cout << "CANCELED: Did you update the subscription info?" << std::endl;
        }
    }
}

int main(int argc, char **argv) {
    setlocale(LC_ALL, "");
    recognizeSpeech();
    return 0;
}
```

用语音资源中的实际值替换 YourSubscriptionKey 值和 YourServiceRegion 值。Replace the YourSubscriptionKey and YourServiceRegion values with actual values from the Speech resource.

  • 导航到 Azure 门户,然后打开语音资源Navigate to the Azure portal , and open the Speech resource
  • 在左侧的“密钥”下,有两个可用的订阅密钥 Under the Keys on the left, there are two available subscription keys
    • 使用其中的任一密钥来替换 YourSubscriptionKeyUse either one as the YourSubscriptionKey value replacement
  • 在左侧的“概览” 下,记下该区域并将其映射到区域标识符Under the Overview on the left, note the region and map it to the region identifier
    • 使用区域标识符 来替换 YourServiceRegion 值,例如:使用 "chinaeast2" 来替换“中国东部 2” Use the Region identifier as the YourServiceRegion value replacement, for example: "chinaeast2" for China East 2

代码说明Code explanation

需要语音资源订阅密钥和区域才能创建语音配置对象。The Speech resource subscription key and region are required to create a speech configuration object. 实例化语音识别器对象需要配置对象。The configuration object is needed to instantiate a speech recognizer object.

识别器实例公开了多种用于识别语音的方法。The recognizer instance exposes multiple ways to recognize speech. 在此示例中识别了一次语音。In this example, speech is recognized once. 此功能是告知语音服务,你要发送单个需识别的短语,并且在该短语被识别后会停止识别语音。This functionality lets the Speech service know that you're sending a single phrase for recognition, and that once the phrase is identified to stop recognizing speech. 生成结果后,代码会将识别原因写入控制台。Once the result is yielded, the code will write the recognition reason to the console.

提示

语音 SDK 将默认使用 en-us 作为语言进行识别。若要了解如何选择源语言,请参阅指定语音转文本的源语言The Speech SDK will default to recognizing using en-us for the language, see Specify source language for speech to text for information on choosing the source language.

生成应用Build the app

备注

请确保将以下命令输入在单个命令行上。Make sure to enter the commands below as a single command line. 执行该操作的最简单方法是使用每个命令旁边的“复制按钮”来复制命令,然后将其粘贴到 shell 提示符下。The easiest way to do that is to copy the command by using the Copy button next to each command, and then paste it at your shell prompt.

  • x64(64 位)系统上,运行以下命令来生成应用程序。On an x64 (64-bit) system, run the following command to build the application.

    g++ helloworld.cpp -o helloworld -I "$SPEECHSDK_ROOT/include/cxx_api" -I "$SPEECHSDK_ROOT/include/c_api" --std=c++14 -lpthread -lMicrosoft.CognitiveServices.Speech.core -L "$SPEECHSDK_ROOT/lib/x64" -l:libasound.so.2
    
  • x86(32 位)系统上,运行以下命令来生成应用程序。On an x86 (32-bit) system, run the following command to build the application.

    g++ helloworld.cpp -o helloworld -I "$SPEECHSDK_ROOT/include/cxx_api" -I "$SPEECHSDK_ROOT/include/c_api" --std=c++14 -lpthread -lMicrosoft.CognitiveServices.Speech.core -L "$SPEECHSDK_ROOT/lib/x86" -l:libasound.so.2
    
  • ARM64(64 位)系统上,运行以下命令生成应用程序。On an ARM64 (64-bit) system, run the following command to build the application.

    g++ helloworld.cpp -o helloworld -I "$SPEECHSDK_ROOT/include/cxx_api" -I "$SPEECHSDK_ROOT/include/c_api" --std=c++14 -lpthread -lMicrosoft.CognitiveServices.Speech.core -L "$SPEECHSDK_ROOT/lib/arm64" -l:libasound.so.2
    

运行应用程序Run the app

  1. 将加载程序的库路径配置为指向语音 SDK 库。Configure the loader's library path to point to the Speech SDK library.

    • x64(64 位)系统上,输入以下命令。On an x64 (64-bit) system, enter the following command.

      export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SPEECHSDK_ROOT/lib/x64"
      
    • x86(32 位)系统上,输入以下命令。On an x86 (32-bit) system, enter this command.

      export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SPEECHSDK_ROOT/lib/x86"
      
    • ARM64(64 位)系统上,输入以下命令。On an ARM64 (64-bit) system, enter the following command.

      export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SPEECHSDK_ROOT/lib/arm64"
      
  2. 运行应用程序。Run the application.

    ./helloworld
    
  3. 在控制台窗口中,会出现一个提示,请求你说点什么。In the console window, a prompt appears, requesting that you say something. 说一个英语短语或句子。Speak an English phrase or sentence. 你的语音将传输到语音服务并转录为文本,该文本将显示在同一窗口中。Your speech is transmitted to the Speech service and transcribed to text, which appears in the same window.

    Say something...
    We recognized: What's the weather like?
    

后续步骤Next steps

了解语音识别的这些基本知识后,请继续浏览基础知识,了解语音 SDK 中的常见功能和任务。With this base knowledge of speech recognition, continue exploring the basics to learn about common functionality and tasks within the Speech SDK.

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK Java 示例You can view or download all Speech SDK Java Samples on GitHub.

选择目标环境Choose your target environment

先决条件Prerequisites

准备工作:Before you get started:

源代码Source code

若要向 Java 项目添加新的空类,请选择“文件” > “新建” > “类”。**** **** ****To add a new empty class to your Java project, select File > New > Class. 在“新建 Java 类”窗口中,在“包”字段内输入 speechsdk.quickstart,在“名称”字段内输入 Main。**** **** ****In the New Java Class window, enter speechsdk.quickstart into the Package field, and Main into the Name field.

“新建 Java 类”窗口的屏幕截图

Main.java 文件的内容替换为以下代码片段:Replace the contents of the Main.java file with the following snippet:

```java
package speechsdk.quickstart;

import java.net.URI;
import java.util.concurrent.Future;
import com.microsoft.cognitiveservices.speech.*;

/**
 * Quickstart: recognize speech using the Speech SDK for Java.
 */
public class Main {

    /**
     * @param args Arguments are ignored in this sample.
     */
    public static void main(String[] args) {
        try {

            int exitCode = 1;
            SpeechConfig config = SpeechConfig.fromSubscription("YourSubscriptionKey", "YourServiceRegion");
            assert(config != null);

            SpeechRecognizer reco = new SpeechRecognizer(config);
            assert(reco != null);

            System.out.println("Say something...");

            Future<SpeechRecognitionResult> task = reco.recognizeOnceAsync();
            assert(task != null);

            SpeechRecognitionResult result = task.get();
            assert(result != null);

            if (result.getReason() == ResultReason.RecognizedSpeech) {
                System.out.println("We recognized: " + result.getText());
                exitCode = 0;
            }
            else if (result.getReason() == ResultReason.NoMatch) {
                System.out.println("NOMATCH: Speech could not be recognized.");
            }
            else if (result.getReason() == ResultReason.Canceled) {
                CancellationDetails cancellation = CancellationDetails.fromResult(result);
                System.out.println("CANCELED: Reason=" + cancellation.getReason());

                if (cancellation.getReason() == CancellationReason.Error) {
                    System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode());
                    System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails());
                    System.out.println("CANCELED: Did you update the subscription info?");
                }
            }

            reco.close();

            System.exit(exitCode);
        } catch (Exception ex) {
            System.out.println("Unexpected exception: " + ex.getMessage());

            assert(false);
            System.exit(1);
        }
    }
}
```

用语音资源中的实际值替换 YourSubscriptionKey 值和 YourServiceRegion 值。Replace the YourSubscriptionKey and YourServiceRegion values with actual values from the Speech resource.

  • 导航到 Azure 门户,然后打开语音资源Navigate to the Azure portal , and open the Speech resource
  • 在左侧的“密钥”下,有两个可用的订阅密钥 Under the Keys on the left, there are two available subscription keys
    • 使用其中的任一密钥来替换 YourSubscriptionKeyUse either one as the YourSubscriptionKey value replacement
  • 在左侧的“概览” 下,记下该区域并将其映射到区域标识符Under the Overview on the left, note the region and map it to the region identifier
    • 使用区域标识符 来替换 YourServiceRegion 值,例如:使用 "chinaeast2" 来替换“中国东部 2” Use the Region identifier as the YourServiceRegion value replacement, for example: "chinaeast2" for China East 2

代码说明Code explanation

需要语音资源订阅密钥和区域才能创建语音配置对象。The Speech resource subscription key and region are required to create a speech configuration object. 实例化语音识别器对象需要配置对象。The configuration object is needed to instantiate a speech recognizer object.

识别器实例公开了多种用于识别语音的方法。The recognizer instance exposes multiple ways to recognize speech. 在此示例中识别了一次语音。In this example, speech is recognized once. 此功能是告知语音服务,你要发送单个需识别的短语,并且在该短语被识别后会停止识别语音。This functionality lets the Speech service know that you're sending a single phrase for recognition, and that once the phrase is identified to stop recognizing speech. 生成结果后,代码会将识别原因写入控制台。Once the result is yielded, the code will write the recognition reason to the console.

提示

语音 SDK 将默认使用 en-us 作为语言进行识别。若要了解如何选择源语言,请参阅指定语音转文本的源语言The Speech SDK will default to recognizing using en-us for the language, see Specify source language for speech to text for information on choosing the source language.

生成并运行应用Build and run app

F11,或选择“运行”**** > “调试”****。Press F11, or select Run > Debug. 接下来的 15 秒,通过麦克风提供的语音输入将被识别并记录到控制台窗口中。The next 15 seconds of speech input from your microphone will be recognized and logged in the console window.

成功识别后的控制台输出的屏幕截图

后续步骤Next steps

了解语音识别的这些基本知识后,请继续浏览基础知识,了解语音 SDK 中的常见功能和任务。With this base knowledge of speech recognition, continue exploring the basics to learn about common functionality and tasks within the Speech SDK.

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK Python 示例You can view or download all Speech SDK Python Samples on GitHub.

先决条件Prerequisites

准备工作:Before you get started:

源代码Source code

创建名为“quickstart.py”的文件并在其中粘贴以下 Python 代码。Create a file named quickstart.py and paste the following Python code in it.

import azure.cognitiveservices.speech as speechsdk

# Creates an instance of a speech config with specified subscription key and service region.
# Replace with your own subscription key and service region (e.g., "chinaeast2").
speech_key, service_region = "YourSubscriptionKey", "YourServiceRegion"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

# Creates a recognizer with the given settings
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

print("Say something...")


# Starts speech recognition, and returns after a single utterance is recognized. The end of a
# single utterance is determined by listening for silence at the end or until a maximum of 15
# seconds of audio is processed.  The task returns the recognition text as result. 
# Note: Since recognize_once() returns only a single utterance, it is suitable only for single
# shot recognition like command or query. 
# For long-running multi-utterance recognition, use start_continuous_recognition() instead.
result = speech_recognizer.recognize_once()

# Checks result.
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
    print("Recognized: {}".format(result.text))
elif result.reason == speechsdk.ResultReason.NoMatch:
    print("No speech could be recognized: {}".format(result.no_match_details))
elif result.reason == speechsdk.ResultReason.Canceled:
    cancellation_details = result.cancellation_details
    print("Speech Recognition canceled: {}".format(cancellation_details.reason))
    if cancellation_details.reason == speechsdk.CancellationReason.Error:
        print("Error details: {}".format(cancellation_details.error_details))

用语音资源中的实际值替换 YourSubscriptionKey 值和 YourServiceRegion 值。Replace the YourSubscriptionKey and YourServiceRegion values with actual values from the Speech resource.

  • 导航到 Azure 门户,然后打开语音资源Navigate to the Azure portal , and open the Speech resource
  • 在左侧的“密钥”下,有两个可用的订阅密钥 Under the Keys on the left, there are two available subscription keys
    • 使用其中的任一密钥来替换 YourSubscriptionKeyUse either one as the YourSubscriptionKey value replacement
  • 在左侧的“概览” 下,记下该区域并将其映射到区域标识符Under the Overview on the left, note the region and map it to the region identifier
    • 使用区域标识符 来替换 YourServiceRegion 值,例如:使用 "chinaeast2" 来替换“中国东部 2” Use the Region identifier as the YourServiceRegion value replacement, for example: "chinaeast2" for China East 2

代码说明Code explanation

需要语音资源订阅密钥和区域才能创建语音配置对象。The Speech resource subscription key and region are required to create a speech configuration object. 实例化语音识别器对象需要配置对象。The configuration object is needed to instantiate a speech recognizer object.

识别器实例公开了多种用于识别语音的方法。The recognizer instance exposes multiple ways to recognize speech. 在此示例中识别了一次语音。In this example, speech is recognized once. 此功能是告知语音服务,你要发送单个需识别的短语,并且在该短语被识别后会停止识别语音。This functionality lets the Speech service know that you're sending a single phrase for recognition, and that once the phrase is identified to stop recognizing speech. 生成结果后,代码会将识别原因写入控制台。Once the result is yielded, the code will write the recognition reason to the console.

提示

语音 SDK 将默认使用 en-us 作为语言进行识别。若要了解如何选择源语言,请参阅指定语音转文本的源语言The Speech SDK will default to recognizing using en-us for the language, see Specify source language for speech to text for information on choosing the source language.

生成并运行应用Build and run app

现在,可以使用语音服务测试语音识别。Now you're ready to test speech recognition using the Speech service.

如果在 macOS 上运行此程序,并且它是使用麦克风构建的第一个 Python 应用,则可能需要为该麦克风指定终端访问权限。If you're running this on macOS and it's the first Python app you've built that uses a microphone, you'll probably need to give Terminal access to the microphone. 打开“系统设置”并选择“安全与隐私” 。Open System Settings and select Security & Privacy. 接下来,选择“隐私”并在列表中找到“麦克风” 。Next, select Privacy and locate Microphone in the list. 最后,选择“终端”并保存。Last, select Terminal and save.

  1. 启动应用 - 在命令行中键入:Start your app - From the command line, type:
    python quickstart.py
    
  2. 开始识别 - 它会提示你说英语短语。Start recognition - It will prompt you to speak a phrase in English. 语音将发送到语音服务,转录为文本,并在控制台中呈现。Your speech is sent to the Speech service, transcribed as text, and rendered in the console.

后续步骤Next steps

了解语音识别的这些基本知识后,请继续浏览基础知识,了解语音 SDK 中的常见功能和任务。With this base knowledge of speech recognition, continue exploring the basics to learn about common functionality and tasks within the Speech SDK.

本快速入门介绍如何使用语音 CLI 通过命令行以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech CLI from the command line to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松使用语音 CLI 来执行常见识别任务,例如转录对话。It's easy to use the Speech CLI to perform common recognition tasks, such as transcribing conversations. 经过一次性配置后,可通过语音 CLI 使用麦克风以交互方式将音频转录为文本,或使用批处理脚本从文件进行转录。After a one-time configuration, the Speech CLI lets you transcribe audio into text interactively with a microphone or from files using a batch script.

下载并安装Download and install

按照以下步骤在 Windows 上安装语音 CLI:Follow these steps to install the Speech CLI on Windows:

  1. 下载语音 CLI zip 存档然后提取它。Download the Speech CLI zip archive, then extract it.
  2. 转到从下载中提取的根目录 spx-zips,并提取所需的子目录(spx-net471 用于 .NET Framework 4.7,spx-netcore-win-x64 用于 x64 CPU 上的 .NET Core 3.0)。Go to the root directory spx-zips that you extracted from the download, and extract the subdirectory that you need (spx-net471 for .NET Framework 4.7, or spx-netcore-win-x64 for .NET Core 3.0 on an x64 CPU).

在命令提示符中,将目录更改到此位置,然后键入 spx 查看语音 CLI 的帮助。In the command prompt, change directory to this location, and then type spx to see help for the Speech CLI.

备注

在 Windows 上,语音 CLI 只能显示本地计算机上命令提示符适用的字体。On Windows, the Speech CLI can only show fonts available to the command prompt on the local computer. Windows 终端支持通过语音 CLI 以交互方式生成的所有字体。Windows Terminal supports all fonts produced interactively by the Speech CLI. 如果输出到文件,文本编辑器(例如记事本)或 web 浏览器(例如 Microsoft Edge)也可以显示所有字体。If you output to a file, a text editor like Notepad or a web browser like Microsoft Edge can also show all fonts.

备注

查找命令时,Powershell 不会检查本地目录。Powershell does not check the local directory when looking for a command. 在 Powershell 中,将目录更改为 spx 的位置,并通过输入 .\spx 调用工具。In Powershell, change directory to the location of spx and call the tool by entering .\spx. 如果将此目录添加到路径,则 Powershell 和 Windows 命令提示符会从不包含 .\ 前缀的任何目录中查找 spxIf you add this directory to your path, Powershell and the Windows command prompt will find spx from any directory without including the .\ prefix.

创建订阅配置Create subscription config

若要开始使用语音 CLI,首先需要输入语音订阅密钥和区域信息。To start using the Speech CLI, you first need to enter your Speech subscription key and region information. 请查看区域支持页,找到你的区域标识符。See the region support page to find your region identifier. 获得订阅密钥和区域标识符后(例如Once you have your subscription key and region identifier (ex. chinaeast2),运行以下命令。chinaeast2), run the following commands.

spx config @key --set SUBSCRIPTION-KEY
spx config @region --set REGION

现在会存储订阅身份验证,用于将来的 SPX 请求。Your subscription authentication is now stored for future SPX requests. 如果需要删除这些已存储值中的任何一个,请运行 spx config @region --clearspx config @key --clearIf you need to remove either of these stored values, run spx config @region --clear or spx config @key --clear.

启用麦克风Enable microphone

插上并打开电脑麦克风,同时关闭任何可能会使用麦克风的应用。Plug in and turn on your PC microphone, and turn off any apps that might also use the microphone. 某些计算机具有内置麦克风,其他计算机则需要配置蓝牙设备。Some computers have a built-in microphone, while others require configuration of a Bluetooth device.

运行语音 CLIRun the Speech CLI

现在,可以运行语音 CLI 来识别来自麦克风的语音。Now you're ready to run the Speech CLI to recognize speech from your microphone.

  1. 启动应用 - 在命令行中,更改为包含语音 CLI 二进制文件的目录,然后键入:Start your app - From the command line, change to the directory that contains the Speech CLI binary file, and type:

    spx recognize --microphone
    

    备注

    语音 CLI 默认为英语。The Speech CLI defaults to English. 你可以从“语音转文本”表中选择不同语言。You can choose a different language from the Speech-to-text table. 例如,添加 --source de-DE 以识别德语语音。For example, add --source de-DE to recognize German speech.

  2. 开始识别 - 向麦克风讲话。Start recognition - Speak into the microphone. 随后可以看到字词会实时转录为文本。You will see transcription of your words into text in real-time. 如果停止说话一段时间,或者按 ctrl-C,语音 CLI 将停止。The Speech CLI will stop after a period of silence, or when you press ctrl-C.

后续步骤Next steps

继续浏览基础知识,了解语音 CLI 的其他功能。Continue exploring the basics to learn about other features of the Speech CLI.

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK Go 示例You can view or download all Speech SDK Go Samples on GitHub.

先决条件Prerequisites

准备工作:Before you get started:

设置环境Setup your environment

通过添加以下行,使用最新的 SDK 版本更新 go.mod 文件Update the go.mod file with the latest SDK version by adding this line

require (
    github.com/Microsoft/cognitive-services-speech-sdk-go v1.13.0
)

从一些样本代码入手Start with some boilerplate code

  1. 将源文件(例如 sr-quickstart.go)的内容替换为以下内容,其中包括:Replace the contents of your source file (e.g. sr-quickstart.go) with the below, which includes:
  • “主要”包定义"main" package definition
  • 从语音 SDK 导入所需的模块importing the necessary modules from the Speech SDK
  • 用于存储订阅信息的变量,本快速入门的后面部分会替换该信息variables for storing the subscription information that will be replaced later in this quickstart
  • 使用麦克风进行音频输入的简单实现a simple implementation using the microphone for audio input
  • 在语音识别期间发生的各种事件的事件处理程序event handlers for various events that take place during a speech recognition
package recognizer

import (
    "bufio"
    "fmt"
    "os"

    "github.com/Microsoft/cognitive-services-speech-sdk-go/audio"
    "github.com/Microsoft/cognitive-services-speech-sdk-go/speech"
)

func recognizingHandler(event speech.SpeechRecognitionEventArgs) {
    defer event.Close()
    fmt.Println("Recognizing:", event.Result.Text)
}

func recognizedHandler(event speech.SpeechRecognitionEventArgs) {
    defer event.Close()
    fmt.Println("Recognized:", event.Result.Text)
}

func cancelledHandler(event speech.SpeechRecognitionCanceledEventArgs) {
    defer event.Close()
    fmt.Println("Received a cancellation: ", event.ErrorDetails)
}

func main() {
    subscription :=  "YOUR_SUBSCRIPTION_KEY"
    region := "YOUR_SUBSCRIPTIONKEY_REGION"

    audioConfig, err := audio.NewAudioConfigFromDefaultMicrophoneInput()
    if err != nil {
        fmt.Println("Got an error: ", err)
        return
    }
    defer audioConfig.Close()
    config, err := speech.NewSpeechConfigFromSubscription(subscription, region)
    if err != nil {
        fmt.Println("Got an error: ", err)
        return
    }
    defer config.Close()
    speechRecognizer, err := speech.NewSpeechRecognizerFromConfig(config, audioConfig)
    if err != nil {
        fmt.Println("Got an error: ", err)
        return
    }
    defer speechRecognizer.Close()
    speechRecognizer.Recognizing(recognizingHandler)
    speechRecognizer.Recognized(recognizedHandler)
    speechRecognizer.Canceled(cancelledHandler)
    speechRecognizer.StartContinuousRecognitionAsync()
    defer speechRecognizer.StopContinuousRecognitionAsync()
    bufio.NewReader(os.Stdin).ReadBytes('\n')
}

用语音资源中的实际值替换 YOUR_SUBSCRIPTION_KEY 值和 YOUR_SUBSCRIPTIONKEY_REGION 值。Replace the YOUR_SUBSCRIPTION_KEY and YOUR_SUBSCRIPTIONKEY_REGION values with actual values from the Speech resource.

  • 导航到 Azure 门户,然后打开语音资源Navigate to the Azure portal, and open the Speech resource
  • 在左侧的“密钥”下,有两个可用的订阅密钥Under the Keys on the left, there are two available subscription keys
    • 使用其中的任一密钥来替换 YOUR_SUBSCRIPTION_KEYUse either one as the YOUR_SUBSCRIPTION_KEY value replacement
  • 在左侧的“概览”下,记下该区域并将其映射到区域标识符Under the Overview on the left, note the region and map it to the region identifier
  • 使用区域标识符来替换 YOUR_SUBSCRIPTIONKEY_REGION 值,例如:使用 "chinaeast2" 来替换“中国东部 2”Use the Region identifier as the YOUR_SUBSCRIPTIONKEY_REGION value replacement, for example: "chinaeast2" for China East 2

代码说明Code explanation

需要语音订阅密钥和区域才能创建语音配置对象。The Speech subscription key and region are required to create a speech configuration object. 实例化语音识别器对象需要配置对象。The configuration object is needed to instantiate a speech recognizer object.

识别器实例公开了多种用于识别语音的方法。The recognizer instance exposes multiple ways to recognize speech. 在此示例中持续识别语音。In this example, speech is continuously recognized. 此功能告知语音服务,你要发送许多需识别的短语,并在程序终止时停止识别语音。This functionality lets the Speech service know that you're sending many phrases for recognition, and when the program terminates to stop recognizing speech. 生成结果后,代码会将它们写入控制台。As results are yielded, the code will write them to the console.

生成并运行Build and run

现在,可以使用语音服务生成项目并测试语音识别。You're now set up to build your project and test speech recognition using the Speech service.

  1. 生成项目,例如“开始生成”Build your project, e.g. "go build"
  2. 运行模块并对着设备的麦克风讲出一个短语或句子。Run the module and speak a phrase or sentence into your device's microphone. 你的语音将传输到语音服务并转录为文本,该文本将显示在输出中。Your speech is transmitted to the Speech service and transcribed to text, which appears in the output.

备注

语音 SDK 将默认使用 en-us 作为语言进行识别。若要了解如何选择源语言,请参阅指定语音转文本的源语言The Speech SDK will default to recognizing using en-us for the language, see Specify source language for speech to text for information on choosing the source language.

后续步骤Next steps

本快速入门介绍如何使用语音 SDK 以交互方式识别来自麦克风输入的语音,以及从捕获的音频中获取听录文本。In this quickstart, you use the Speech SDK to interactively recognize speech from a microphone input, and get the text transcription from captured audio. 可轻松地将此功能集成到应用或设备中,用于执行对话听录等常见识别任务。It's easy to integrate this feature into your apps or devices for common recognition tasks, such as transcribing conversations. 它还可用于更加复杂的集成,例如配合使用 Bot Framework 和语音 SDK 来生成语音助手。It can also be used for more complex integrations, like using the Bot Framework with the Speech SDK to build voice assistants.

满足几个先决条件后,通过麦克风识别语音只需四个步骤:After satisfying a few prerequisites, recognizing speech from a microphone only takes four steps:

  • 通过订阅密钥和区域创建 SpeechConfig 对象。Create a SpeechConfig object from your subscription key and region.
  • 使用以上的 SpeechConfig 对象创建 SpeechRecognizer 对象。Create a SpeechRecognizer object using the SpeechConfig object from above.
  • 使用 SpeechRecognizer 对象,开始单个言语的识别过程。Using the SpeechRecognizer object, start the recognition process for a single utterance.
  • 检查返回的 SpeechRecognitionResultInspect the SpeechRecognitionResult returned.

可以在 GitHub 上查看或下载所有语音 SDK JavaScript 示例You can view or download all Speech SDK JavaScript Samples on GitHub.

先决条件Prerequisites

准备工作:Before you get started:

新建网站文件夹Create a new Website folder

新建空文件夹。Create a new, empty folder. 如果要在 web 服务器上承载示例,请确保 web 服务器可访问文件夹。In case you want to host the sample on a web server, make sure that the web server can access the folder.

将 JavaScript 的语音 SDK 解压缩到文件夹Unpack the Speech SDK for JavaScript into that folder

将语音 SDK 作为 .zip 包下载,并将其解压缩到新建文件夹。Download the Speech SDK as a .zip package and unpack it into the newly created folder. 这导致两个文件(microsoft.cognitiveservices.speech.sdk.bundle.jsmicrosoft.cognitiveservices.speech.sdk.bundle.js.map)被解压缩。This results in two files being unpacked, microsoft.cognitiveservices.speech.sdk.bundle.js and microsoft.cognitiveservices.speech.sdk.bundle.js.map. 后一个文件是可选的,可用于调试到 SDK 代码中。The latter file is optional, and is useful for debugging into the SDK code.

创建 index.html 页面Create an index.html page

在文件夹中创建名为 index.html 的新文件,使用文本编辑器打开此文件。Create a new file in the folder, named index.html and open this file with a text editor.

  1. 创建以下 HTML 框架:Create the following HTML skeleton:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>
      <meta charset="utf-8" />
    </head>
    <body style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size:13px;">
      <!-- <uidiv> -->
      <div id="warning">
        <h1 style="font-weight:500;">Speech Recognition Speech SDK not found (microsoft.cognitiveservices.speech.sdk.bundle.js missing).</h1>
      </div>
    
      <div id="content" style="display:none">
        <table width="100%">
          <tr>
            <td></td>
            <td><h1 style="font-weight:500;">Microsoft Cognitive Services Speech SDK JavaScript Quickstart</h1></td>
          </tr>
          <tr>
            <td align="right"><a href="https://docs.azure.cn/cognitive-services/speech-service/get-started" target="_blank">Subscription</a>:</td>
            <td><input id="subscriptionKey" type="text" size="40" value="subscription"></td>
          </tr>
          <tr>
            <td align="right">Region</td>
            <td><input id="serviceRegion" type="text" size="40" value="YourServiceRegion"></td>
          </tr>
          <tr>
            <td></td>
            <td><button id="startRecognizeOnceAsyncButton">Start recognition</button></td>
          </tr>
          <tr>
            <td align="right" valign="top">Results</td>
            <td><textarea id="phraseDiv" style="display: inline-block;width:500px;height:200px"></textarea></td>
          </tr>
        </table>
      </div>
      <!-- </uidiv> -->
    
      <!-- <speechsdkref> -->
      <!-- Speech SDK reference sdk. -->
      <script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
      <!-- </speechsdkref> -->
    
      <!-- <authorizationfunction> -->
      <!-- Speech SDK Authorization token -->
      <script>
      // Note: Replace the URL with a valid endpoint to retrieve
      //       authorization tokens for your subscription.
      var authorizationEndpoint = "token.php";
    
      function RequestAuthorizationToken() {
        if (authorizationEndpoint) {
          var a = new XMLHttpRequest();
          a.open("GET", authorizationEndpoint);
          a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          a.send("");
          a.onload = function() {
              var token = JSON.parse(atob(this.responseText.split(".")[1]));
              serviceRegion.value = token.region;
              authorizationToken = this.responseText;
              subscriptionKey.disabled = true;
              subscriptionKey.value = "using authorization token (hit F5 to refresh)";
              console.log("Got an authorization token: " + token);
          }
        }
      }
      </script>
      <!-- </authorizationfunction> -->
    
      <!-- <quickstartcode> -->
      <!-- Speech SDK USAGE -->
      <script>
        // status fields and start button in UI
        var phraseDiv;
        var startRecognizeOnceAsyncButton;
    
        // subscription key and region for speech services.
        var subscriptionKey, serviceRegion;
        var authorizationToken;
        var SpeechSDK;
        var recognizer;
    
        document.addEventListener("DOMContentLoaded", function () {
          startRecognizeOnceAsyncButton = document.getElementById("startRecognizeOnceAsyncButton");
          subscriptionKey = document.getElementById("subscriptionKey");
          serviceRegion = document.getElementById("serviceRegion");
          phraseDiv = document.getElementById("phraseDiv");
    
          startRecognizeOnceAsyncButton.addEventListener("click", function () {
            startRecognizeOnceAsyncButton.disabled = true;
            phraseDiv.innerHTML = "";
    
            // if we got an authorization token, use the token. Otherwise use the provided subscription key
            var speechConfig;
            if (authorizationToken) {
              speechConfig = SpeechSDK.SpeechConfig.fromAuthorizationToken(authorizationToken, serviceRegion.value);
            } else {
              if (subscriptionKey.value === "" || subscriptionKey.value === "subscription") {
                alert("Please enter your Microsoft Cognitive Services Speech subscription key!");
                return;
              }
              speechConfig = SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey.value, serviceRegion.value);
            }
    
            speechConfig.speechRecognitionLanguage = "en-US";
            var audioConfig  = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
            recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
    
            recognizer.recognizeOnceAsync(
              function (result) {
                startRecognizeOnceAsyncButton.disabled = false;
                phraseDiv.innerHTML += result.text;
                window.console.log(result);
    
                recognizer.close();
                recognizer = undefined;
              },
              function (err) {
                startRecognizeOnceAsyncButton.disabled = false;
                phraseDiv.innerHTML += err;
                window.console.log(err);
    
                recognizer.close();
                recognizer = undefined;
              });
          });
    
          if (!!window.SpeechSDK) {
            SpeechSDK = window.SpeechSDK;
            startRecognizeOnceAsyncButton.disabled = false;
    
            document.getElementById('content').style.display = 'block';
            document.getElementById('warning').style.display = 'none';
    
            // in case we have a function for getting an authorization token, call it.
            if (typeof RequestAuthorizationToken === "function") {
                RequestAuthorizationToken();
            }
          }
        });
      </script>
      <!-- </quickstartcode> -->
    </body>
    </html>
    

创建令牌源(可选)Create the token source (optional)

如果要在 web 服务器上承载网页,可以为演示应用程序提供令牌源。In case you want to host the web page on a web server, you can optionally provide a token source for your demo application. 这样一来,订阅密钥永远不会离开服务器,并且用户可以在不输入任何授权代码的情况下使用语音功能。That way, your subscription key will never leave your server while allowing users to use speech capabilities without entering any authorization code themselves.

创建名为 token.php 的新文件。Create a new file named token.php. 此示例假设 Web 服务器在启用 cURL 的情况下支持 PHP 脚本语言。In this example we assume your web server supports the PHP scripting language with curl enabled. 输入以下代码:Enter the following code:

<?php
header('Access-Control-Allow-Origin: ' . $_SERVER['SERVER_NAME']);

// Replace with your own subscription key and service region (e.g., "chinaeast2").
$subscriptionKey = 'YourSubscriptionKey';
$region = 'YourServiceRegion';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $region . '.api.cognitive.azure.cn/sts/v1.0/issueToken');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Ocp-Apim-Subscription-Key: ' . $subscriptionKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
?>

备注

授权令牌仅具有有限的生存期。Authorization tokens only have a limited lifetime. 此简化示例不显示如何自动刷新授权令牌。This simplified example does not show how to refresh authorization tokens automatically. 作为用户,你可以手动重载页面或点击 F5 刷新。As a user, you can manually reload the page or hit F5 to refresh.

在本地生成和运行示例Build and run the sample locally

要启动应用,双击 index.html 文件或使用你喜欢的 web 浏览器打开 index.html。To launch the app, double-click on the index.html file or open index.html with your favorite web browser. 随即显示的简单 GUI 允许你输入订阅密钥和区域以及使用麦克风触发识别。It will present a simple GUI allowing you to enter your subscription key and region and trigger a recognition using the microphone.

备注

此方法对 Safari 浏览器不起作用。This method doesn't work on the Safari browser. 在 Safari 上,示例网页需要托管在 Web 服务器上;Safari 不允许从本地文件加载的网站使用麦克风。On Safari, the sample web page needs to be hosted on a web server; Safari doesn't allow websites loaded from a local file to use the microphone.

通过 web 服务器生成并运行示例Build and run the sample via a web server

要启动应用,打开你最喜欢的 web 浏览器,将其指向承载文件夹的公共 URL,输入你的区域,使用麦克风触发识别。To launch your app, open your favorite web browser and point it to the public URL that you host the folder on, enter your region, and trigger a recognition using the microphone. 配置后,它将获取令牌源中的令牌。If configured, it will acquire a token from your token source.

后续步骤Next steps

了解语音识别的这些基本知识后,请继续浏览基础知识,了解语音 SDK 中的常见功能和任务。With this base knowledge of speech recognition, continue exploring the basics to learn about common functionality and tasks within the Speech SDK.

查看或下载 GitHub 上所有的语音 SDK 示例View or download all Speech SDK Samples on GitHub.

其他语言和平台支持Additional language and platform support

重要

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

如果已单击此选项卡,则可能看不到采用你偏好的编程语言的快速入门。If you've clicked this tab, you probably didn't see a quickstart in your favorite programming language. 别担心,我们在 GitHub 上提供了其他快速入门材料和代码示例。Don't worry, we have additional quickstart materials and code samples available on GitHub. 使用表格查找适用于编程语言和平台/OS 组合的相应示例。Use the table to find the right sample for your programming language and platform/OS combination.

语言Language 其他快速入门Additional Quickstarts 代码示例Code samples
C#C# 来自文件来自 blobFrom file, From blob .NET Framework.NET CoreUWPUnityXamarin.NET Framework, .NET Core, UWP, Unity, Xamarin
C++C++ 来自文件来自 blobFrom file, From blob WindowsLinuxmacOSWindows, Linux, macOS
JavaJava 来自文件来自 blobFrom file, From blob AndroidJREAndroid, JRE
JavaScriptJavaScript 在浏览器上识别来自麦克风的语音在 Node.js 上识别来自文件的语音Browser from mic, Node.js from file Windows、Linux 和 macOSWindows, Linux, macOS
Objective-CObjective-C [iOS][obj-iOS-qck]、[macOS][obj-macOS-qck][iOS][obj-iOS-qck], [macOS][obj-macOS-qck] iOSmacOSiOS, macOS
PythonPython 来自文件来自 blobFrom file, From blob Windows、Linux 和 macOSWindows, Linux, macOS
SwiftSwift [iOS][swift-iOS-qck]、[macOS][swift-macOS-qck][iOS][swift-iOS-qck], [macOS][swift-macOS-qck] iOSmacOSiOS, macOS