使用 Azure 门户创建认知服务帐户Create a Cognitive Services account using the Azure portal

本快速入门介绍如何注册 Azure 认知服务和创建具有单服务或多服务订阅的帐户。In this quickstart, you'll learn how to sign up for Azure Cognitive Services and create an account that has a single-service or multi-service subscription. 这些服务由 Azure 资源表示,允许连接到一个或多个 Azure 认知服务 API。These services are represented by Azure resources, which enable you to connect to one or many of the Azure Cognitive Services APIs.

先决条件Prerequisites

Azure 认知服务订阅类型Azure Cognitive Service subscription types

Note

订阅所有者可以通过应用 Azure 策略,分配“不允许的资源类型”策略定义并指定“Microsoft.CognitiveServices/accounts”作为目标资源类型来禁止为资源组和订阅创建认知服务帐户 。Subscription owners can disable the creation of Cognitive Services accounts for resource groups and subscriptions by applying Azure policy, assigning a “Not allowed resource types” policy definition, and specifying Microsoft.CognitiveServices/accounts as the target resource type.

可以通过两种不同的订阅来访问 Azure 认知服务:多服务订阅或单服务订阅。You can access Azure Cognitive Services through two different subscriptions: A multi-service subscription, or a single-service one. 通过这些订阅,可以同时连接到单个服务或多个服务。These subscriptions let you connect to either a single service or multiple services at once.

多服务订阅Multi-service subscription

Azure 认知服务的多服务订阅允许你对大多数 Azure 认知服务使用单个订阅和 Azure 资源,并合并所使用的服务的计费。A multi-service subscription for Azure Cognitive Services lets you use a single subscription and Azure resource for most of the Azure Cognitive Services, and consolidates billing from the services you use. 请参阅认知服务定价了解其他信息。See Cognitive Services pricing for additional information.

单服务订阅Single-service subscription

订阅单一服务,如计算机视觉或语音服务。A subscription to a single service, such as Computer Vision or the Speech Services. 单服务订阅仅限于该资源。A single-service subscription is restricted to that resource.

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

在创建资源前,必须具有 Azure 资源组。Before creating a resource, you must have an Azure resource group. 每个认知服务帐户(及其关联的 Azure 资源)都必须属于某个 Azure 资源组。Every Cognitive Services account (and its associated Azure resource) must belong to an Azure resource group. 在创建帐户时,可以选择新建资源组,或使用现有的资源组。When you create an account, you have the option to either create a new resource group, or use an existing one. 本文介绍如何创建新资源组。This article shows how to create a new resource group.

  1. 登录 Azure 门户,然后单击“创建资源” 。Sign in to the Azure portal, and click +Create a resource.

    选择认知服务 API

  2. 可以通过以下方式查找可用的认知服务:You can find available Cognitive Services with in the following ways:

    • 使用搜索栏,并输入要订阅的服务的名称。Use the search bar and enter the name of the service you want to subscribe to.

      • 若要创建多服务订阅的资源,请在搜索栏中输入“认知服务” ,然后选择“认知服务” 资源。To create a resource for a multi-service subscription, enter Cognitive Services in the search bar, and select the Cognitive Services resource.

      搜索“认知服务”

    • 若要查看所有可用认知服务,请选择“Azure 市场”下的“AI + 机器学习” 。To see all available cognitive services, select AI + Machine Learning, under Azure Marketplace. 如果看不到你感兴趣的服务,请单击“查看全部”,并滚动到“认知服务” 。If you don't see the service you're interested in, click on See all and scroll to Cognitive Services. 单击“更多” 以查看认知服务 API 的整个目录。Click More to view the entire catalog of Cognitive Services APIs.

      选择认知服务 API

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

    Important

    请记住你的 Azure 位置,因为在调用 Azure 认知服务时可能需要用到它。Remember your Azure location, as you may need it when calling the Azure Cognitive Services.

    名称Name 认知服务资源的描述性名称。A descriptive name for your cognitive services resource. 建议使用描述性的名称,例如“MyCognitiveServicesAccount” 。We recommend using a descriptive name, for example MyCognitiveServicesAccount.
    订阅Subscription 选择一个可用的 Azure 订阅。Select one of your available Azure subscriptions.
    LocationLocation 认知服务实例的位置。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.

    “创建资源”屏幕

获取订阅的密钥Get the keys for your subscription

创建资源后,如果已固定该资源,则可以从 Azure 仪表板对其进行访问。After creating your resource, you can access it from the Azure dashboard if you pinned it. 否则,可以在“资源组”中查找该资源 。Otherwise, you can find it in Resource Groups. 在选择了资源后,可以通过选择“资源管理”下的“密钥”获取所需的密钥 。After selecting your resource, you can get the keys by selecting Keys under Resource Management.

配置用于身份验证的环境变量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.

  • WindowsWindows

    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.

  • LinuxLinux

    export COGNITIVE_SERVICE_KEY=your-key
    

    添加环境变量后,请从控制台窗口运行 source ~/.bashrc,使更改生效。After you add the environment variable, run source ~/.bashrc from your console window to make the changes effective.

  • macOSmacOS

    编辑 .bash_profile,然后添加环境变量:Edit your .bash_profile, and add the environment variable:

    export COGNITIVE_SERVICE_KEY=your-key
    

    添加环境变量后,请从控制台窗口运行 source .bash_profile,使更改生效。After you add the environment variable, run source .bash_profile from your console window to make the changes effective.

清理资源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 associated with the resource group.

若要使用 Azure 门户删除资源组,请执行以下操作:To remove a resource group using the Azure portal:

  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 to delete, and right-click the More button (...) on the right side of the listing.
  3. 选择“删除资源组”并进行确认。 Select Delete resource group, and confirm.

另请参阅See also