建立認知服務帳戶使用 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 中的一個或多個 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

注意

訂用帳戶擁有者可以藉由套用 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

警告

目前,以下服務支援多服務金鑰:QnA Maker、 語音服務、 自訂的視覺和異常偵測器。At this time, these services don't support multi-service keys: QnA Maker, Speech Services, Custom Vision, and Anomaly Detector.

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.

      搜尋認知服務

    • 若要查看所有可用的認知服務,請選取AI + 機器學習服務下方Azure MarketplaceTo 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:

    重要

    因為您可能需要呼叫 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