I am trying to make a PHP application using which I can send a .flac file to the google speech service and get text in return.
Following the official guide
This is the authentication code:
require 'vendor/autoload.php';
use Google\Cloud\Core\ServiceBuilder;
// Authenticate using keyfile data
$cloud = new ServiceBuilder([
'keyFile' => json_decode(file_get_contents('b.json'), true)
]);
Then this is the speech code:
use Google\Cloud\Speech\SpeechClient;
$speech = new SpeechClient([
'languageCode' => 'en-US'
]);
// Recognize the speech in an audio file.
$results = $speech->recognize(
fopen(__DIR__ . '/audio_sample.flac', 'r')
);
foreach ($results as $result) {
echo $result->topAlternative()['transcript'] . "\n";
}
Of course the $cloud variable is never used. Where should it go?
I ran it nonetheless got
Uncaught exception 'Google\Cloud\Core\Exception\ServiceException' with message '{ "error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }
I just want to make a simple query. Any help would be appreciated.