Hi
I want know where I must put the API key?
I have this error:
Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information
I share my code. Thanks
$speech = new SpeechClient([
'projectId' => 'PROJECT_ID'
]);
$recognizeOptions = [
'encoding' => 'LINEAR16',
'languageCode' => 'fr-FR',
'sampleRate' => 16000,
];
// Recognize the speech in an audio file.
$results = $speech->recognize(
fopen(__DIR__ . $pathUploads.'/'.$fileAudio, 'r'),
$recognizeOptions
);
Have you obtained a service account keyfile from the console? If not, check out this guide (scroll down to the "On Your Own Server" section).
Once you have your keyfile, update your code like so:
$speech = new SpeechClient([
'keyFilePath' => '/path/to/keyfile.json'
]);
Make sure to change the /path/to/keyfile.json part to point at the key you downloaded from your developer's console.
If you're using GCE or App Engine, you shouldn't need to worry about this, but it doesn't appear that you are.
If you prefer not to worry about passing your keyfile into the API client, you can make use of the Application Default Credentials to automatically authenticate when you create a client. In this case, your code would look like this:
$speech = new SpeechClient();
Let me know if you have any trouble getting authenticated after following these instructions. :)
Hey @gustavo4, did you have any luck with this?
@jdpedrie Thanks, now it's ok.
But how to using API key for testing only instead of "Service account" for the Authentication?
@songliqiangcn Any luck with your question? Were you able to find a solution?
Hi all, how do I use API key isntead of the json key file?
@Purus we currently do not have support for using an API key in speech.
@michaelbausor if it sounds good to you I'd be happy to add this in.
We were planning to have the SpeechClient authenticated by using either the Service account or the API keys based on the users preference. Is it possible as of today?
$client = new SpeechClient([
'credentials' => PATH_TO_CONFIG_FILE
]);
Most helpful comment
@jdpedrie Thanks, now it's ok.