Speech/src/SpeechClient.php
public function beginRecognizeOperation($audio, array $options = [])
    {
        $response = $this->connection->longRunningRecognize(
            $this->formatRequest($audio, $options)
        );

        return new Operation(
            $this->connection,
            $response['name'],
            $response
        );
    }
public function beginRecognizeOperation($audio, array $options = [])
    {
        $response = $this->connection->longRunningRecognize(
            $this->formatRequest($audio, $options)
        );

        return new Operation(
            $this->connection,
            $response['name'],
            $response
        );
    }
public function beginRecognizeOperation ( $ audio , array $ options = [ ] ) { $ response = $ this -> connection -> longRunningRecognize ( $ this -> formatRequest ( $ audio , $ options ) ) ; return new Operation ( $ this -> connection , $ response [ 'name' ] , $ response ) ; }
Runs a recognize request as an operation. Ideal when working with audio
longer than approximately one minute. Requires polling of the returned
operation in order to fetch results.

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();
}

$result = $operation->results()[0];
print_r($result->topAlternative());
```

```
// Run with speech contexts, sample rate, and encoding provided
$operation = $speech->beginRecognizeOperation(
fopen(__DIR__  . '/audio.flac', 'r'), [
'encoding' => 'FLAC',
'sampleRateHertz' => 16000,
'speechContexts' => [
[
'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();
}

$result = $operation->results()[0];
print_r($result->topAlternative());
```

@codingStandardsIgnoreStart
@see https://cloud.google.com/speech/reference/rest/v1/operations Operations
@see https://cloud.google.com/speech/reference/rest/v1/speech/longrunningrecognize LongRunningRecognize API documentation
@see https://cloud.google.com/speech/reference/rest/v1/RecognitionConfig#AudioEncoding AudioEncoding types
@see https://cloud.google.com/speech/docs/best-practices Speech API best practices
@codingStandardsIgnoreEnd

@param resource|string|StorageObject $audio The audio to recognize. May
be a resource, string of bytes, a URI pointing to a
Google Cloud Storage object in the format of
`gs://{bucket-name}/{object-name}` or a
{@see Google\Cloud\Storage\StorageObject}.
@param array $options [optional] {
Configuration options.

@type bool $detectGcsUri When providing $audio as a string, this flag
determines whether or not to attempt to detect if the string
represents a Google Cloud Storage URI in the format of
`gs://{bucket-name}/{object-name}`. **Defaults to** `true`.
@type string $languageCode The language of the content. BCP-47
(e.g., `"en-US"`, `"es-ES"`) language codes are accepted. See
[Language Support](https://cloud.google.com/speech/docs/languages)
for a list of the currently supported language codes. This
value will be required if a default has not been set on the
client. **Defaults to** the value set on the client.
@type int $sampleRateHertz Sample rate in Hertz of the provided
audio. Valid values are: 8000-48000. 16000 is optimal. For best
results, set the sampling rate of the audio source to 16000 Hz.
If that's not possible, use the native sample rate of the audio
source (instead of re-sampling). For .flac and .wav files the
Speech API will make a best effort to read the sample rate from
the file's headers.
@type string $encoding Encoding of the provided audio. May be one of
`"LINEAR16"`, `"FLAC"`, `"MULAW"`, `"AMR"`, `"AMR_WB"`. For
.flac and .wav files the Speech API will make a best effort to
determine the encoding type from the file's headers.
@type int $maxAlternatives Maximum number of alternatives to be
returned. Valid values are 1-30. **Defaults to** `1`.
@type bool $profanityFilter If set to `true`, the server will attempt
to filter out profanities, replacing all but the initial
character in each filtered word with asterisks, e.g. \"f***\".
**Defaults to** `false`.
@type array $speechContexts A list of arrays where each element must
contain a key `phrases`. Each key `phrases` should contain an
array of strings which provide "hints" to the speech recognizer
to favor specific words and phrases in the results. Please see
[SpeechContext](https://cloud.google.com/speech/reference/rest/v1/RecognitionConfig#SpeechContext)
for more information.
@type bool $enableWordTimeOffsets If set to `true`, a list of
`wordTimeOffsets` are returned with the top alternative. If
`false` or omitted, no `wordTimeOffsets` are returned.
**Defaults to** `false`.
}
@return Operation
@throws \InvalidArgumentException
Runs a recognize request as an operation . Ideal when working with audio longer than approximately one minute . Requires polling of the returned operation in order to fetch results .