'Speech to text api - use morethen 1min audio using rest api show error

When i select audio morethen 30sec or 1min then its show below error

--> Sync input too long. For audio longer than 1 min use LongRunningRecognize with a 'uri' parameter.

-> https://speech.googleapis.com/v1p1beta1/speech:recognize?key="api key"

body -> {
"audio":{"content":" // base64 formated audio // "},
"config":{
    "enableAutomaticPunctuation":true,
    "encoding":"WEBM_OPUS",
    "sampleRateHertz": 16000,
    "languageCode":"en-US",
    "model":"default"
    }
    }


Solution 1:[1]

You should use speech:longrunningrecognize endpoint for audio longer than 1 minute.

The endpoint with key is https://speech.googleapis.com/v1/speech:longrunningrecognize?key="api_key"

Using curl I can send a request to this endpoint:

curl -s -H "Content-Type: application/json" \
   https://speech.googleapis.com/v1/speech:longrunningrecognize?key=AIzaSyD....\
   -d "{
  'config': {
    'language_code': 'en-US'
  },
  'audio':{
    'uri':'gs://cloud-samples-tests/speech/brooklyn.flac'
  }
}"

Output:

{
  "name": "1521059426290567438"
}

When a request is sent to the endpoint, it will create a long running operation and it will return a name. This will be used to check the status of the long running operation. You can check the status by sending a request to this endpoint https://speech.googleapis.com/v1/operations/<name>. If the operation is done, it will return the transcript in the response.

Check status:

curl -H "Content-Type: application/json; charset=utf-8" \
     "https://speech.googleapis.com/v1/operations/1521059426290567438?key=AIzaSyD...."

Output:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ricco D