3

For authentication Cloud Speech-To-Text client in PHP application I use the following:

 $credentials = 'C:\cred.json';
 $client=new SpeechClient(['credentials'=>json_decode(file_get_contents($credentials), true)]);

For some reasons I receive error:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response: {"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}

The above method of authentication works perfectly in Text-To-Speech API.

$credentials = 'C:\cred.json';
$client = new TextToSpeechClient(['credentials' => json_decode(file_get_contents($credentials), true)]);

What is wrong/missing?

  • 1
    I ran into the same problem, but in my case is opposite. Speech-To-Text is working like a charm but Text-To-Speech produces the error you mentioned. Did you manage to solve this? – jacek Dec 17 '20 at 19:18

2 Answers2

5

The problem solved by updating Auth module (in Vendor folder). Just change your Auth version to the latest version in your composer.json file.

{
    "require": {
        "google/auth": "1.14.3",
        "google/cloud-text-to-speech": "^0.5.0",
        "google/cloud-speech": "^1.3",
        "google/protobuf": "^3.14",
        "phpmailer/phpmailer": "^6.1",
        "google/apiclient": "2.5"
    }
}

Once it's done, I just run

composer update

in your command line in the appropriate directory. Now it works.

  • 2
    This saved my day! I rather not add sub-dependencies to my composer or run `composer update` which would update all other libraries as well. Running `composer update google/cloud-text-to-speech --with-dependencies` worked fine as well. Alternatively you could run `composer show` and check which dependencies you may need updating (in my case it worked if I updated "google/auth","google/gax" and "google/cloud-core") – Kevin Driessen Feb 09 '21 at 11:29
1

I'd like to outline the suggest of @KevinDriessen in the comment because solve the problem (I got the same issue) without a general update of the vendor directory, that is not always desiderable.

composer update google/cloud-text-to-speech --with-dependencies
Ivan Buttinoni
  • 4,110
  • 1
  • 24
  • 44