0
votes

I am new to use the google API's. I am trying to use the google speech recognition, to convert my speech to text and vise versa. But don't know how to use the google speech API. I download the google cloud package using this command

composer require google/cloud

But I dont know how to use this. I am following tutorial https://github.com/GoogleCloudPlatform/google-cloud-php from this link. but it showing me errors.

Fatal error:  Uncaught Google\Cloud\Exception\ServiceException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php:221
Stack trace:

#0 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(185): Google\Cloud\RequestWrapper->convertToGoogleException(Object(DomainException))
#1 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(167): Google\Cloud\RequestWrapper->fetchCredentials()
#2 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(150): Google\Cloud\RequestWrapper->getToken()
#3 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(131): Google\Cloud\RequestWrapper->signRequest(Object(GuzzleHttp\Psr7\Request))
#4 /var/www/html/googlevoice/vendor/google/cloud/src/RestTrait.php(78): Google\Cloud\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#5 /var/www/html/googlevoice/vendor/goo in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php on line 221
1
And what happens when you follow the link given to you in the message itself? ---> developers.google.com/accounts/docs/…DaImTo
I did not getting any thing. I just getting the above errors.Satvinder Jeet
Go though creating the credentials tutorial again. Your code cant read it.DaImTo

1 Answers

0
votes

First things first it looks like you need to generate your service account credentials :).

Please take a look at this guide in order to get that set up: https://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/guides/authentication

From there you'll want to do the following:

require 'vendor/autoload.php';

use Google\Cloud\Storage\StorageClient;

// Pass the key file directly into your client.
$storage = new StorageClient([
    'keyFilePath' => '/path/to/service/credentials.json'
]);

// OR

// Store the key file as an environment variable
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/credentials.json');

$storage = new StorageClient();