快速入门:使用 Azure 门户创建认知服务资源Quickstart: Create a Cognitive Services resource using the Azure portal

使用此快速入门开始使用 Azure 认知服务。Use this quickstart to start using Azure Cognitive Services. 在 Azure 门户中创建认知服务资源后,你将获得用于验证应用程序的终结点和密钥。After creating a Cognitive Service resource in the Azure portal, you'll get an endpoint and a key for authenticating your applications.

Azure 认知服务是包含 REST API 和客户端库 SDK 的基于云的服务,可帮助开发人员将认知智能内置于应用程序,而无需具备直接的人工智能 (AI) 或数据科学技能或知识。Azure Cognitive Services are cloud-based services with REST APIs, and client library SDKs available to help developers build cognitive intelligence into applications without having direct artificial intelligence (AI) or data science skills or knowledge. 借助 Azure 认知服务,开发人员可以通过能够看、听、说、理解甚至开始推理的认知解决方案,轻松将认知功能添加到他们的应用程序中。Azure Cognitive Services enables developers to easily add cognitive features into their applications with cognitive solutions that can see, hear, speak, understand, and even begin to reason.

可以通过两种不同的资源访问 Azure 认知服务:多服务资源或单服务资源。You can access Azure Cognitive Services through two different resources: A multi-service resource, or a single-service one.

  • 多服务资源:Multi-service resource:
    • 使用单个密钥和终结点访问多个 Azure 认知服务。Access multiple Azure Cognitive Services with a single key and endpoint.
    • 合并来自你使用的服务的计费。Consolidates billing from the services you use.
  • 单服务资源:Single-service resource:
    • 对于创建的每个服务,使用唯一密钥和终结点访问单个 Azure 认知服务。Access a single Azure Cognitive Service with a unique key and endpoint for each service created.
    • 使用免费层试用服务。Use the free tier to try out the service.

先决条件Prerequisites

新建 Azure 认知服务资源Create a new Azure Cognitive Services resource

  1. 创建资源。Create a resource.

    多服务资源在门户中名为“认知服务”。The multi-service resource is named Cognitive Services in the portal. 创建认知服务资源Create a Cognitive Services resource.

    此时,多服务资源允许访问以下认知服务:At this time, the multi-service resource enables access to the following Cognitive Services:

    • 计算机视觉Computer Vision
    • 内容审查器Content Moderator
    • 人脸Face
    • 语言理解 (LUIS)Language Understanding (LUIS)
    • 文本分析Text Analytics
    • 转换器Translator
<span data-ttu-id="9b526-124">使用以下链接为可用的认知服务创建资源:</span><span class="sxs-lookup"><span data-stu-id="9b526-124">Use the below links to create a resource for the available Cognitive Services:</span></span>

| <span data-ttu-id="9b526-125">影像</span><span class="sxs-lookup"><span data-stu-id="9b526-125">Vision</span></span>                      | <span data-ttu-id="9b526-126">语音</span><span class="sxs-lookup"><span data-stu-id="9b526-126">Speech</span></span>                  | <span data-ttu-id="9b526-127">语言</span><span class="sxs-lookup"><span data-stu-id="9b526-127">Language</span></span>                          | <span data-ttu-id="9b526-128">决策</span><span class="sxs-lookup"><span data-stu-id="9b526-128">Decision</span></span>             |
|-----------------------------|-------------------------|-----------------------------------|----------------------|
| [<span data-ttu-id="9b526-129">计算机视觉</span><span class="sxs-lookup"><span data-stu-id="9b526-129">Computer vision</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesComputerVision)         | [<span data-ttu-id="9b526-130">语音服务</span><span class="sxs-lookup"><span data-stu-id="9b526-130">Speech Services</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesSpeechServices)     | [<span data-ttu-id="9b526-131">沉浸式阅读器</span><span class="sxs-lookup"><span data-stu-id="9b526-131">Immersive reader</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesImmersiveReader)              | [<span data-ttu-id="9b526-132">异常检测器</span><span class="sxs-lookup"><span data-stu-id="9b526-132">Anomaly Detector</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesAnomalyDetector) |
| [<span data-ttu-id="9b526-133">自定义视觉服务</span><span class="sxs-lookup"><span data-stu-id="9b526-133">Custom vision service</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesCustomVision) | [<span data-ttu-id="9b526-134">说话人识别</span><span class="sxs-lookup"><span data-stu-id="9b526-134">Speaker Recognition</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesSpeakerRecognition) | [<span data-ttu-id="9b526-135">语言理解 (LUIS)</span><span class="sxs-lookup"><span data-stu-id="9b526-135">Language Understanding (LUIS)</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesLUISAllInOne) | [<span data-ttu-id="9b526-136">内容审查器</span><span class="sxs-lookup"><span data-stu-id="9b526-136">Content Moderator</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesContentModerator) |
| [<span data-ttu-id="9b526-137">人脸</span><span class="sxs-lookup"><span data-stu-id="9b526-137">Face</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesFace)                    |                         | [<span data-ttu-id="9b526-138">QnA Maker</span><span class="sxs-lookup"><span data-stu-id="9b526-138">QnA Maker</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesQnAMaker)                     | [<span data-ttu-id="9b526-139">个性化体验创建服务</span><span class="sxs-lookup"><span data-stu-id="9b526-139">Personalizer</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesPersonalizer)     |
|           |                         | [<span data-ttu-id="9b526-140">翻译</span><span class="sxs-lookup"><span data-stu-id="9b526-140">Translator</span></span>](https://portal.azure.cn/#create/Microsoft.CognitiveServicesTextTranslation)               |                      |

**_
  1. 在“创建”页中提供以下信息:On the _ Create* page, provide the following information:

    名称Name 认知服务资源的描述性名称。A descriptive name for your cognitive services resource. 例如,MyCognitiveServicesResourceFor example, MyCognitiveServicesResource.
    订阅Subscription 选择一个可用的 Azure 订阅。Select one of your available Azure subscriptions.
    位置Location 认知服务实例的位置。The location of your cognitive service instance. 不同位置可能会导致延迟,但不会影响资源的运行时可用性。Different locations may introduce latency, but have no impact on the runtime availability of your resource.
    定价层Pricing tier 认知服务帐户的费用取决于你所选的选项和你的使用情况。The cost of your Cognitive Services account depends on the options you choose and your usage. 有关详细信息,请参阅 API 定价详细信息For more information, see the API pricing details.
    资源组Resource group 将包含认知服务资源的 Azure 资源组。The Azure resource group that will contain your Cognitive Services resource. 可以创建新组或将其添加到预先存在的组。You can create a new group or add it to a pre-existing group.

    多服务资源创建屏幕

    单击 创建Click Create.

提示

如果订阅不允许创建认知服务资源,则可能需要使用 Azure 门户PowerShell 命令Azure CLI 命令启用 Azure 资源提供程序的功能。If your subscription doesn't allow you to create a Cognitive Service resource, you may need to enable that ability of the Azure resource provider with the Azure portal, PowerShell command or an Azure CLI command. 如果你不是订阅所有者,可请求订阅所有者或具有管理员角色的人员帮助你完成注册,或请求向你的帐户授予 /register/action 特权 。If you are not the subscription owner, ask the Subscription Owner or someone with a role of admin to complete the registration for you or ask for the /register/action privileges granted to your account.

获取资源的密钥Get the keys for your resource

  1. 成功部署资源后,单击“后续步骤”下的“转到资源”。After your resource is successfully deployed, click on _ Go to resource* under Next Steps.

    搜索“认知服务”

  2. 从打开的快速入门窗格中,可以访问密钥和终结点。From the quickstart pane that opens, you can access your key and endpoint.

    获取密钥和终结点

配置用于身份验证的环境变量Configure an environment variable for authentication

应用程序需要对它们使用的认知服务的访问进行身份验证。Applications need to authenticate access to the Cognitive Services they use. 若要进行身份验证,我们建议创建一个环境变量来存储 Azure 资源的密钥。To authenticate, we recommend creating an environment variable to store the keys for your Azure Resources.

获得密钥后,将其写入运行应用程序的本地计算机上的新环境变量。After you have your key, write it to a new environment variable on the local machine running the application. 若要设置环境变量,请打开控制台窗口,并遵照适用于操作系统的说明。To set the environment variable, open a console window, and follow the instructions for your operating system. your-key 替换为资源的密钥之一。Replace your-key with one of the keys for your resource.

setx COGNITIVE_SERVICE_KEY "your-key"

添加环境变量后,可能需要重启任何正在运行的、需要读取环境变量的程序(包括控制台窗口)。After you add the environment variable, you may need to restart any running programs that will need to read the environment variable, including the console window. 例如,如果使用 Visual Studio 作为编辑器,请在运行示例之前重启 Visual Studio。For example, if you are using Visual Studio as your editor, restart Visual Studio before running the example.

清理资源Clean up resources

如果想要清理并删除认知服务订阅,可以删除资源或资源组。If you want to clean up and remove a Cognitive Services subscription, you can delete the resource or resource group. 删除资源组也会删除该组中包含的任何其他资源。Deleting the resource group also deletes any other resources contained in the group.

  1. 在 Azure 门户中展开左侧的菜单,打开服务菜单,然后选择“资源组”以显示资源组的列表。In the Azure portal, expand the menu on the left side to open the menu of services, and choose Resource Groups to display the list of your resource groups.
  2. 找到包含要删除的资源的资源组。Locate the resource group containing the resource to be deleted
  3. 右键单击资源组列表。Right-click on the resource group listing. 选择“删除资源组”并进行确认。Select Delete resource group, and confirm.

另请参阅See also