Deploy the Speech service container to Azure Container Instances

Learn how to deploy the Cognitive Services Speech service container to Azure Container Instances. This procedure demonstrates the creation of an Azure Speech service resource. Then we discuss pulling the associated container image. Finally, we highlight the ability to exercise the orchestration of the two from a browser. Using containers can shift the developers' attention away from managing infrastructure to instead focusing on application development.

Prerequisites

  • Use an Azure subscription. If you don't have an Azure subscription, create a free account before you begin.
  • Install the Azure CLI (az).
  • Docker engine and validate that the Docker CLI works in a console window.

Request access to the container registry

You must first complete and submit the Cognitive Services Speech Containers Request form to request access to the container.

The form requests information about you, your company, and the user scenario for which you'll use the container. After you've submitted the form, the Azure Cognitive Services team reviews it to ensure that you meet the criteria for access to the private container registry.

Important

You must use an email address that's associated with either a Microsoft Account (MSA) or Azure Active Directory (Azure AD) account in the form.

If your request is approved, you'll receive an email with instructions that describe how to obtain your credentials and access the private container registry.

Create a Speech resource

  1. Sign into the Azure portal

  2. Click Create Speech resource

  3. Enter all required settings:

    Setting Value
    Name Desired name (2-64 characters)
    Subscription Select appropriate subscription
    Location Select any nearby and available location
    Pricing Tier F0 - the minimal pricing tier
    Resource Group Select an available resource group
  4. Click Create and wait for the resource to be created. After it is created, navigate to the resource page

  5. Collect configured endpoint and an API key:

    Resource Tab in Portal Setting Value
    Overview Endpoint Copy the endpoint. It looks similar to https://speech.cognitiveservices.azure.com/sts/v1.0/issuetoken
    Keys API Key Copy 1 of the two keys. It is a 32 alphanumeric-character string with no spaces or dashes, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

Create an Azure Container Instance resource from the Azure CLI

The YAML below defines the Azure Container Instance resource. Copy and paste the contents into a new file, named my-aci.yaml and replace the commented values with your own. Refer to the template format for valid YAML. Refer to the container repositories and images for the available image names and their corresponding repository. For more information of the YAML reference for Container instances, see YAML reference: Azure Container Instances.

apiVersion: 2018-10-01
location: # < Valid location >
name: # < Container Group name >
properties:
  imageRegistryCredentials: # This is only required if you are pulling a non-public image that requires authentication to access.
  - server: containerpreview.azurecr.io
    username: # < The username for the preview container registry >
    password: # < The password for the preview container registry >
  containers:
  - name: # < Container name >
    properties:
      image: # < Repository/Image name >
      environmentVariables: # These env vars are required
        - name: eula
          value: accept
        - name: billing
          value: # < Service specific Endpoint URL >
        - name: apikey
          value: # < Service specific API key >
      resources:
        requests:
          cpu: 4 # Always refer to recommended minimal resources
          memoryInGb: 8 # Always refer to recommended minimal resources
      ports:
        - port: 5000
  osType: Linux
  volumes: # This node, is only required for container instances that pull their model in at runtime, such as LUIS.
  - name: aci-file-share
    azureFile:
      shareName: # < File share name >
      storageAccountName: # < Storage account name>
      storageAccountKey: # < Storage account key >
  restartPolicy: OnFailure
  ipAddress:
    type: Public
    ports:
    - protocol: tcp
      port: 5000
tags: null
type: Microsoft.ContainerInstance/containerGroups

Note

Not all locations have the same CPU and Memory availability. Refer to the location and resources table for the listing of available resources for containers per location and OS.

We'll rely on the YAML file we created for the az container create command. From the Azure CLI, execute the az container create command replacing the <resource-group> with your own. Additionally, for securing values within a YAML deployment refer to secure values.

az container create -g <resource-group> -f my-aci.yaml

The output of the command is Running... if valid, after sometime the output changes to a JSON string representing the newly created ACI resource. The container image is more than likely not be available for a while, but the resource is now deployed.

Tip

Pay close attention to the locations of public preview Azure Cognitive Service offerings, as the YAML will needed to be adjusted accordingly to match the location.

Validate that a container is running

There are several ways to validate that the container is running. Locate the External IP address and exposed port of the container in question, and open your favorite web browser. Use the various request URLs below to validate the container is running. The example request URLs listed below are http://localhost:5000, but your specific container may vary. Keep in mind that you're to rely on your container's External IP address and exposed port.

Request URL Purpose
http://localhost:5000/ The container provides a home page.
http://localhost:5000/ready Requested with GET, this provides a verification that the container is ready to accept a query against the model. This request can be used for Kubernetes liveness and readiness probes.
http://localhost:5000/status Also requested with GET, this verifies if the api-key used to start the container is valid without causing an endpoint query. This request can be used for Kubernetes liveness and readiness probes.
http://localhost:5000/swagger The container provides a full set of documentation for the endpoints and a Try it out feature. With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

Container's home page

Next steps

Let's continue working with Azure Cognitive Services containers.