使用 Azure 门户创建认知服务资源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 认知服务:多服务资源或单服务资源。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 Text
  2. 在“创建”页中提供以下信息: 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.

获取资源的密钥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