PHP で Google Speech API を使用して音声からテキストを読み込もうとしていますが、次のエラーで失敗します: request must contain 'config' field.
これはコードです:
<?php
require '../lib/vendor/autoload.php';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setAuthConfig(__DIR__.'/config.json');
$client->authorize();
$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false)));
$client->setHttpClient($guzzleClient);
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$speechService = new Google_Service_Speech($client);
$syncRecognize = new Google_Service_Speech_SyncRecognizeRequest();
$config = new Google_Service_Speech_RecognitionConfig();
$config->audioChannels = 1;
$config->encoding = 'LINEAR16';//'audio/wav';
$config->sampleRate = 8000;
$audio = new Google_Service_Speech_RecognitionAudio();
$audio->setContent(file_get_contents('c1.wav'));
$syncRecognize->setAudio($audio);
$syncRecognize->setConfig($config);
$response = $speechService->speech->syncrecognize($syncRecognize);
私は以下を受け取ります:
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{
"error": {
"code": 400,
"message": "Invalid recognition 'config': request must contain 'config' field.",
"errors": [
{
"message": "Invalid recognition 'config': request must contain 'config' field.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
PHP のドキュメントが見つからないので、助けていただければ幸いです。