Quickstart: Query the API

Prerequisites

  1. Complete all required steps in the before you begin quickstart.
  2. Deploy the API .

Overview

You can query the API using the same methods regardless of which installation method you used. How you query the API depends on whether or not you have configured a public endpoint. If your endpoint is not public, you will need to determine how to expose the API yourself. There are many options for doing this, including creating an Ingress if your cluster supports it, publishing the created service , running Istio , and so on.

The steps outlined below walk you through querying an endpoint. There are two methods:

  1. Query the endpoint from within your cluster (no public IP required).
  2. Query a public IP.

Query the internal DNS name (no public IP required)

This example runs a query from within the cluster using the Domain Name Service (DNS) name assigned to the service: $NAME.$NAMESPACE , such as speech.speech. You can either set the environment variables or replace them with actual value in the commands.

  1. Create a new job within the cluster to query the API from. If this job already exists in the cluster, you should remove it first.

      kubectl 
      
     delete 
      
     jobs 
     . 
     batch 
      
     - 
     n 
      
     $ 
     NAMESPACE 
      
     query 
     - 
     api 
     echo 
      
     "apiVersion: batch/v1 
     kind: Job 
     metadata: 
     name: query-api 
     namespace: $NAMESPACE 
     spec: 
     template: 
     metadata: 
     annotations: 
     sidecar.istio.io/inject: 'false' 
     labels: 
     app: query 
     spec: 
     containers: 
     - name: entrypoint 
     image: gcr.io/cloud-marketplace/speech-onprem/speech-to-text-on-prem:$VERSION 
     command: [" 
     / 
     bin 
     / 
     sh 
     ", " 
     - 
     c 
     "] 
     args: 
     - curl https://raw.githubusercontent.com/GoogleCloudPlatform/python-docs-samples/master/speech/snippets/resources/commercial_mono.wav --output /tmp/audio.wav; 
     /bin/onprem_client --address=$NAME.$NAMESPACE:443 --file_paths /tmp/audio.wav 
     restartPolicy: Never 
     " 
      
     | 
      
     kubectl 
      
     apply 
      
     - 
     f 
      
     - 
     
    
  2. Check the logs to see the transcript:

     kubectl logs -n $NAMESPACE --follow $(kubectl get po -n $NAMESPACE -l
    app=query -o=jsonpath='{.items[0].metadata.name}') -c entrypoint 
    

Query a public IP

If you installed Istio in your cluster, make sure that you have Istio Ingress Gateway running with a public IP. If you haven't installed Istio you can set the value for $PUBLIC_IP . Once this is completed, you can submit transcription queries to a public endpoint.

  1. If you have Istio installed, follow the instructions to get the Ingress public IP and set it to PUBLIC_IP .

  2. If you don't have Istio installed, validate that the IP address was bound. It should appear under EXTERNAL-IP below. If it doesn't appear after a few minutes, navigate to your cluster in the console for troubleshooting.

     kubectl get service $NAME --namespace $NAMESPACE 
    
    1. Copy the onprem_client binary from the docker image:

       kubectl cp -n $NAMESPACE $(kubectl get pod -n $NAMESPACE -l
      app.kubernetes.io/name=$NAME -o=jsonpath='{.items[0].metadata.name}'
      ):/bin/onprem_client ./onprem_client
      
      kubectl cp -n $NAMESPACE $(kubectl get pod -n $NAMESPACE -l
      app.kubernetes.io/name=$NAME -o=jsonpath='{.items[0].metadata.name}'
      ):/usr/grte.tar ./grte.tar
      
      sudo tar -xvf grte.tar -C /
      
      chmod a+x ./onprem_client 
      
    2. Use the onprem_client binary to submit a query:

       ./onprem_client  
      --address  
       ${ 
       PUBLIC_IP 
       } 
      :443
      --file_paths  
      /path/to/audio.wav 
      

What's next

Learn how to send a transcription request to the Speech-to-Text On-Prem API.

Create a Mobile Website
View Site in Mobile | Classic
Share by: