The Google Cloud Client Library will attempt to infer the sample rate
and encoding used by the provided audio file for you. This feature is
recommended only if you are unsure of what the values may be and is
currently limited to .flac, .amr, and .awb file types. The sample rate
cannot be inferred from audio provided from a Google Storage object.
For longer audio, up to approximately 80 minutes, you must use Google
Cloud Storage objects as input. In addition to this restriction, only
LINEAR16 audio encoding can be used for long audio inputs.
Example:
$operation = $speech->beginRecognizeOperation(
fopen(__DIR__ . '/audio.flac', 'r')
);
$isComplete = $operation->isComplete();
while (!$isComplete) {
sleep(1); // let's wait for a moment...
$operation->reload();
$isComplete = $operation->isComplete();
}
print_r($operation->results());
Run with speech context, sample rate, and encoding provided
$operation = $speech->beginRecognizeOperation(
fopen(__DIR__ . '/audio.flac', 'r'), [
'encoding' => 'FLAC',
'sampleRate' => 16000,
'speechContext' => [
'phrases' => [
'The Google Cloud Platform',
'Speech API'
]
]
]);
$isComplete = $operation->isComplete();
while (!$isComplete) {
sleep(1); // let's wait for a moment...
$operation->reload();
$isComplete = $operation->isComplete();
}
print_r($operation->results());