Не могу понять, почему нет вывода из этого запроса. Я загрузил 44100 Гц mp3 в этом. Он просто выводит пустой объект через dd (). Я не думаю, что это как-то связано с полномочиями. Поскольку iv включил API из Google Cloud Console.
$speech = new SpeechClient([
'credentials' => storage_path("app/compute/google/cloud/service_accounts/keys/key1.json"),
]);
$file = file_get_contents($options["input_url"]);
// change these variables if necessary
$encoding = AudioEncoding::LINEAR16;
$sampleRateHertz = 44100;
$languageCode = 'en-US';
// get contents of a file into a string
// set string as audio content
$audio = (new RecognitionAudio())
->setContent($file);
// set config
$config = (new RecognitionConfig())
->setEncoding($encoding)
->setSampleRateHertz($sampleRateHertz)
->setLanguageCode($languageCode);
$response = $speech->recognize($config, $audio);
dd(($response->serializeToJsonString()));
foreach ($response->getResults() as $result) {
$alternatives = $result->getAlternatives();
$mostLikely = $alternatives[0];
$transcript = $mostLikely->getTranscript();
$confidence = $mostLikely->getConfidence();
$this->info('Transcript: %s' . PHP_EOL, $transcript);
$this->info('Confidence: %s' . PHP_EOL, $confidence);
}
}