Cloud Speech V2 Client - Class SpeechClient (1.7.0)

Reference documentation and code samples for the Cloud Speech V2 Client class SpeechClient.

Service Description: Enables speech transcription and resource management.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

 $speechClient = new SpeechClient();
try {
    $formattedRecognizer = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $operationResponse = $speechClient->batchRecognize($formattedRecognizer);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->batchRecognize($formattedRecognizer);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'batchRecognize');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Methods

configName

Formats a string containing the fully-qualified path to represent a config resource.

Parameters
Name
Description
project
string
location
string
Returns
Type
Description
string
The formatted config resource.

cryptoKeyName

Formats a string containing the fully-qualified path to represent a crypto_key resource.

Parameters
Name
Description
project
string
location
string
keyRing
string
cryptoKey
string
Returns
Type
Description
string
The formatted crypto_key resource.

cryptoKeyVersionName

Formats a string containing the fully-qualified path to represent a crypto_key_version resource.

Parameters
Name
Description
project
string
location
string
keyRing
string
cryptoKey
string
cryptoKeyVersion
string
Returns
Type
Description
string
The formatted crypto_key_version resource.

customClassName

Formats a string containing the fully-qualified path to represent a custom_class resource.

Parameters
Name
Description
project
string
location
string
customClass
string
Returns
Type
Description
string
The formatted custom_class resource.

locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
Name
Description
project
string
location
string
Returns
Type
Description
string
The formatted location resource.

phraseSetName

Formats a string containing the fully-qualified path to represent a phrase_set resource.

Parameters
Name
Description
project
string
location
string
phraseSet
string
Returns
Type
Description
string
The formatted phrase_set resource.

recognizerName

Formats a string containing the fully-qualified path to represent a recognizer resource.

Parameters
Name
Description
project
string
location
string
recognizer
string
Returns
Type
Description
string
The formatted recognizer resource.

parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • config: projects/{project}/locations/{location}/config
  • cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}
  • cryptoKeyVersion: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}
  • customClass: projects/{project}/locations/{location}/customClasses/{custom_class}
  • location: projects/{project}/locations/{location}
  • phraseSet: projects/{project}/locations/{location}/phraseSets/{phrase_set}
  • recognizer: projects/{project}/locations/{location}/recognizers/{recognizer}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name
Description
formattedName
string

The formatted name string

template
string

Optional name of template to match

Returns
Type
Description
array
An associative array from name component IDs to component values.

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
Name
Description
operationName
string

The name of the long running operation

methodName
string

The name of the method used to start the operation

Returns
Type
Description

__construct

Constructor.

Parameters
Name
Description
options
array

Optional. Options for configuring the service API wrapper.

↳ serviceAddress
string

Deprecated. This option will be removed in a future major release. Please utilize the $apiEndpoint option instead.

↳ apiEndpoint
string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials
string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage : In addition, this option can also accept a pre-constructed {@see} object or {@see} object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig
array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see {@see} .

↳ disableRetries
bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false .

↳ clientConfig
string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport
string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc . Defaults to grpc if gRPC support is detected on the system. Advanced usage : Additionally, it is possible to pass in an already instantiated {@see} object. Note that when this object is provided, any settings in $transportConfig, and any $serviceAddress setting, will be ignored.

↳ transportConfig
array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the {@see} and {@see} methods for the supported options.

↳ clientCertSource
callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

batchRecognize

Performs batch asynchronous speech recognition: send a request with N audio files and receive a long running operation that can be polled to see when the transcriptions are finished.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedRecognizer = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $operationResponse = $speechClient->batchRecognize($formattedRecognizer);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->batchRecognize($formattedRecognizer);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'batchRecognize');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
recognizer
string

Required. Resource name of the recognizer to be used for ASR.

optionalArgs
array

Optional.

↳ config
RecognitionConfig

Features and audio metadata to use for the Automatic Speech Recognition. This field in combination with the config_mask field can be used to override parts of the default_recognition_config of the Recognizer resource.

↳ configMask
FieldMask

The list of fields in config that override the values in the default_recognition_config of the recognizer during this recognition request. If no mask is provided, all given fields in config override the values in the recognizer for this recognition request. If a mask is provided, only the fields listed in the mask override the config in the recognizer for this recognition request. If a wildcard ( * ) is provided, config completely overrides and replaces the config in the recognizer for this recognition request.

↳ files
BatchRecognizeFileMetadata[]

Audio files with file metadata for ASR.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

createCustomClass

Creates a CustomClass .

Sample code:

 $speechClient = new SpeechClient();
try {
    $customClass = new CustomClass();
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    $operationResponse = $speechClient->createCustomClass($customClass, $formattedParent);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->createCustomClass($customClass, $formattedParent);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'createCustomClass');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
customClass
Google\Cloud\Speech\V2\CustomClass

Required. The CustomClass to create.

parent
string

Required. The project and location where this CustomClass will be created. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the CustomClass, but do not actually create it.

↳ customClassId
string

The ID to use for the CustomClass, which will become the final component of the CustomClass's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

createPhraseSet

Creates a PhraseSet .

Sample code:

 $speechClient = new SpeechClient();
try {
    $phraseSet = new PhraseSet();
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    $operationResponse = $speechClient->createPhraseSet($phraseSet, $formattedParent);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->createPhraseSet($phraseSet, $formattedParent);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'createPhraseSet');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
phraseSet
Google\Cloud\Speech\V2\PhraseSet

Required. The PhraseSet to create.

parent
string

Required. The project and location where this PhraseSet will be created. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the PhraseSet, but do not actually create it.

↳ phraseSetId
string

The ID to use for the PhraseSet, which will become the final component of the PhraseSet's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

createRecognizer

Creates a Recognizer .

Sample code:

 $speechClient = new SpeechClient();
try {
    $recognizer = new Recognizer();
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    $operationResponse = $speechClient->createRecognizer($recognizer, $formattedParent);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->createRecognizer($recognizer, $formattedParent);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'createRecognizer');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
recognizer
Google\Cloud\Speech\V2\Recognizer

Required. The Recognizer to create.

parent
string

Required. The project and location where this Recognizer will be created. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the Recognizer, but do not actually create it.

↳ recognizerId
string

The ID to use for the Recognizer, which will become the final component of the Recognizer's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

deleteCustomClass

Deletes the CustomClass .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');
    $operationResponse = $speechClient->deleteCustomClass($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->deleteCustomClass($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'deleteCustomClass');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the CustomClass to delete. Format: projects/{project}/locations/{location}/customClasses/{custom_class}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the deleted CustomClass, but do not actually delete it.

↳ allowMissing
bool

If set to true, and the CustomClass is not found, the request will succeed and be a no-op (no Operation is recorded in this case).

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

deletePhraseSet

Deletes the PhraseSet .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');
    $operationResponse = $speechClient->deletePhraseSet($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->deletePhraseSet($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'deletePhraseSet');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the PhraseSet to delete. Format: projects/{project}/locations/{location}/phraseSets/{phrase_set}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the deleted PhraseSet, but do not actually delete it.

↳ allowMissing
bool

If set to true, and the PhraseSet is not found, the request will succeed and be a no-op (no Operation is recorded in this case).

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

deleteRecognizer

Deletes the Recognizer .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $operationResponse = $speechClient->deleteRecognizer($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->deleteRecognizer($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'deleteRecognizer');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the Recognizer to delete. Format: projects/{project}/locations/{location}/recognizers/{recognizer}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the deleted Recognizer, but do not actually delete it.

↳ allowMissing
bool

If set to true, and the Recognizer is not found, the request will succeed and be a no-op (no Operation is recorded in this case).

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

getConfig

Returns the requested Config .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->configName('[PROJECT]', '[LOCATION]');
    $response = $speechClient->getConfig($formattedName);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the config to retrieve. There is exactly one config resource per project per location. The expected format is projects/{project}/locations/{location}/config .

optionalArgs
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

getCustomClass

Returns the requested CustomClass .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');
    $response = $speechClient->getCustomClass($formattedName);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the CustomClass to retrieve. The expected format is projects/{project}/locations/{location}/customClasses/{custom_class} .

optionalArgs
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

getPhraseSet

Returns the requested PhraseSet .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');
    $response = $speechClient->getPhraseSet($formattedName);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the PhraseSet to retrieve. The expected format is projects/{project}/locations/{location}/phraseSets/{phrase_set} .

optionalArgs
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

getRecognizer

Returns the requested Recognizer . Fails with NOT_FOUND if the requested recognizer doesn't exist.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $response = $speechClient->getRecognizer($formattedName);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the Recognizer to retrieve. The expected format is projects/{project}/locations/{location}/recognizers/{recognizer} .

optionalArgs
array

Optional.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

listCustomClasses

Lists CustomClasses.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    // Iterate over pages of elements
    $pagedResponse = $speechClient->listCustomClasses($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $speechClient->listCustomClasses($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
parent
string

Required. The project and location of CustomClass resources to list. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ pageSize
int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken
string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ showDeleted
bool

Whether, or not, to show resources that have been deleted.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

listPhraseSets

Lists PhraseSets.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    // Iterate over pages of elements
    $pagedResponse = $speechClient->listPhraseSets($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $speechClient->listPhraseSets($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
parent
string

Required. The project and location of PhraseSet resources to list. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ pageSize
int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken
string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ showDeleted
bool

Whether, or not, to show resources that have been deleted.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

listRecognizers

Lists Recognizers.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedParent = $speechClient->locationName('[PROJECT]', '[LOCATION]');
    // Iterate over pages of elements
    $pagedResponse = $speechClient->listRecognizers($formattedParent);
    foreach ($pagedResponse->iteratePages() as $page) {
        foreach ($page as $element) {
            // doSomethingWith($element);
        }
    }
    // Alternatively:
    // Iterate through all elements
    $pagedResponse = $speechClient->listRecognizers($formattedParent);
    foreach ($pagedResponse->iterateAllElements() as $element) {
        // doSomethingWith($element);
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
parent
string

Required. The project and location of Recognizers to list. The expected format is projects/{project}/locations/{location} .

optionalArgs
array

Optional.

↳ pageSize
int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken
string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ showDeleted
bool

Whether, or not, to show resources that have been deleted.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

recognize

Performs synchronous Speech recognition: receive results after all audio has been sent and processed.

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedRecognizer = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $response = $speechClient->recognize($formattedRecognizer);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
recognizer
string

Required. The name of the Recognizer to use during recognition. The expected format is projects/{project}/locations/{location}/recognizers/{recognizer} .

optionalArgs
array

Optional.

↳ config
RecognitionConfig

Features and audio metadata to use for the Automatic Speech Recognition. This field in combination with the config_mask field can be used to override parts of the default_recognition_config of the Recognizer resource.

↳ configMask
FieldMask

The list of fields in config that override the values in the default_recognition_config of the recognizer during this recognition request. If no mask is provided, all non-default valued fields in config override the values in the recognizer for this recognition request. If a mask is provided, only the fields listed in the mask override the config in the recognizer for this recognition request. If a wildcard ( * ) is provided, config completely overrides and replaces the config in the recognizer for this recognition request.

↳ content
string

The audio data bytes encoded as specified in RecognitionConfig . As with all bytes fields, proto buffers use a pure binary representation, whereas JSON representations use base64.

↳ uri
string

URI that points to a file that contains audio data bytes as specified in RecognitionConfig . The file must not be compressed (for example, gzip). Currently, only Google Cloud Storage URIs are supported, which must be specified in the following format: gs://bucket_name/object_name (other URI formats return INVALID_ARGUMENT ). For more information, see Request URIs .

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

streamingRecognize

Performs bidirectional streaming speech recognition: receive results while sending audio. This method is only available via the gRPC API (not REST).

Sample code:

 $speechClient = new SpeechClient();
try {
    $recognizer = 'recognizer';
    $request = new StreamingRecognizeRequest();
    $request->setRecognizer($recognizer);
    // Write all requests to the server, then read all responses until the
    // stream is complete
    $requests = [
        $request,
    ];
    $stream = $speechClient->streamingRecognize();
    $stream->writeAll($requests);
    foreach ($stream->closeWriteAndReadAll() as $element) {
        // doSomethingWith($element);
    }
    // Alternatively:
    // Write requests individually, making read() calls if
    // required. Call closeWrite() once writes are complete, and read the
    // remaining responses from the server.
    $requests = [
        $request,
    ];
    $stream = $speechClient->streamingRecognize();
    foreach ($requests as $request) {
        $stream->write($request);
        // if required, read a single response from the stream
        $element = $stream->read();
        // doSomethingWith($element)
    }
    $stream->closeWrite();
    $element = $stream->read();
    while (!is_null($element)) {
        // doSomethingWith($element)
        $element = $stream->read();
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
optionalArgs
array

Optional.

↳ timeoutMillis
int

Timeout to use for this call.

Returns
Type
Description

undeleteCustomClass

Undeletes the CustomClass .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');
    $operationResponse = $speechClient->undeleteCustomClass($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->undeleteCustomClass($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'undeleteCustomClass');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the CustomClass to undelete. Format: projects/{project}/locations/{location}/customClasses/{custom_class}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the undeleted CustomClass, but do not actually undelete it.

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

undeletePhraseSet

Undeletes the PhraseSet .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');
    $operationResponse = $speechClient->undeletePhraseSet($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->undeletePhraseSet($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'undeletePhraseSet');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the PhraseSet to undelete. Format: projects/{project}/locations/{location}/phraseSets/{phrase_set}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the undeleted PhraseSet, but do not actually undelete it.

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

undeleteRecognizer

Undeletes the Recognizer .

Sample code:

 $speechClient = new SpeechClient();
try {
    $formattedName = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
    $operationResponse = $speechClient->undeleteRecognizer($formattedName);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->undeleteRecognizer($formattedName);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'undeleteRecognizer');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
name
string

Required. The name of the Recognizer to undelete. Format: projects/{project}/locations/{location}/recognizers/{recognizer}

optionalArgs
array

Optional.

↳ validateOnly
bool

If set, validate the request and preview the undeleted Recognizer, but do not actually undelete it.

↳ etag
string

This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

updateConfig

Updates the Config .

Sample code:

 $speechClient = new SpeechClient();
try {
    $config = new Config();
    $response = $speechClient->updateConfig($config);
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
config
Google\Cloud\Speech\V2\Config

Required. The config to update. The config's name field is used to identify the config to be updated. The expected format is projects/{project}/locations/{location}/config .

optionalArgs
array

Optional.

↳ updateMask
FieldMask

The list of fields to be updated.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

updateCustomClass

Updates the CustomClass .

Sample code:

 $speechClient = new SpeechClient();
try {
    $customClass = new CustomClass();
    $operationResponse = $speechClient->updateCustomClass($customClass);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->updateCustomClass($customClass);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'updateCustomClass');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
customClass
Google\Cloud\Speech\V2\CustomClass

Required. The CustomClass to update. The CustomClass's name field is used to identify the CustomClass to update. Format: projects/{project}/locations/{location}/customClasses/{custom_class} .

optionalArgs
array

Optional.

↳ updateMask
FieldMask

The list of fields to be updated. If empty, all fields are considered for update.

↳ validateOnly
bool

If set, validate the request and preview the updated CustomClass, but do not actually update it.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

updatePhraseSet

Updates the PhraseSet .

Sample code:

 $speechClient = new SpeechClient();
try {
    $phraseSet = new PhraseSet();
    $operationResponse = $speechClient->updatePhraseSet($phraseSet);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->updatePhraseSet($phraseSet);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'updatePhraseSet');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
phraseSet
Google\Cloud\Speech\V2\PhraseSet

Required. The PhraseSet to update. The PhraseSet's name field is used to identify the PhraseSet to update. Format: projects/{project}/locations/{location}/phraseSets/{phrase_set} .

optionalArgs
array

Optional.

↳ updateMask
FieldMask

The list of fields to update. If empty, all non-default valued fields are considered for update. Use * to update the entire PhraseSet resource.

↳ validateOnly
bool

If set, validate the request and preview the updated PhraseSet, but do not actually update it.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

updateRecognizer

Updates the Recognizer .

Sample code:

 $speechClient = new SpeechClient();
try {
    $recognizer = new Recognizer();
    $operationResponse = $speechClient->updateRecognizer($recognizer);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $speechClient->updateRecognizer($recognizer);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $speechClient->resumeOperation($operationName, 'updateRecognizer');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $speechClient->close();
} 
Parameters
Name
Description
recognizer
Google\Cloud\Speech\V2\Recognizer

Required. The Recognizer to update. The Recognizer's name field is used to identify the Recognizer to update. Format: projects/{project}/locations/{location}/recognizers/{recognizer} .

optionalArgs
array

Optional.

↳ updateMask
FieldMask

The list of fields to update. If empty, all non-default valued fields are considered for update. Use * to update the entire Recognizer resource.

↳ validateOnly
bool

If set, validate the request and preview the updated Recognizer, but do not actually update it.

↳ retrySettings
RetrySettings|array

Retry settings to use for this call. Can be a {@see} object, or an associative array of retry settings parameters. See the documentation on {@see} for example usage.

Returns
Type
Description

Constants

SERVICE_NAME

  Value: 'google.cloud.speech.v2.Speech' 
 

The name of the service.

SERVICE_ADDRESS

  Value: 'speech.googleapis.com' 
 

The default address of the service.

DEFAULT_SERVICE_PORT

  Value: 443 
 

The default port of the service.

CODEGEN_NAME

  Value: 'gapic' 
 

The name of the code generator, to be included in the agent header.

Design a Mobile Site
View Site in Mobile | Classic
Share by: