Cloud Speech V2 Client - Class SpeechClient (1.12.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
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted config resource.

cryptoKeyName

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

Parameters
NameDescription
project string
location string
keyRing string
cryptoKey string
Returns
TypeDescription
stringThe formatted crypto_key resource.

cryptoKeyVersionName

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

Parameters
NameDescription
project string
location string
keyRing string
cryptoKey string
cryptoKeyVersion string
Returns
TypeDescription
stringThe formatted crypto_key_version resource.

customClassName

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

Parameters
NameDescription
project string
location string
customClass string
Returns
TypeDescription
stringThe formatted custom_class resource.

locationName

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

Parameters
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted location resource.

phraseSetName

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

Parameters
NameDescription
project string
location string
phraseSet string
Returns
TypeDescription
stringThe formatted phrase_set resource.

recognizerName

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

Parameters
NameDescription
project string
location string
recognizer string
Returns
TypeDescription
stringThe 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
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

getOperationsClient

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

Returns
TypeDescription
Google\ApiCore\LongRunning\OperationsClient

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
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ 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 Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper 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 Google\ApiCore\CredentialsWrapper::build() .

↳ 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 Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint 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 Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() 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.

Parameters
NameDescription
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. The maximum number of files allowed to be specified is 5.

↳ recognitionOutputConfig RecognitionOutputConfig

Configuration options for where to output the transcripts of each file.

↳ processingStrategy int

Processing strategy to use for this request. For allowed values, use constants defined on Google\Cloud\Speech\V2\BatchRecognizeRequest\ProcessingStrategy

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\BatchRecognizeResponse;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedRecognizer Resource name of the recognizer to be used for ASR. Please see
 *                                    {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function batch_recognize_sample(string $formattedRecognizer): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->batchRecognize($formattedRecognizer);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var BatchRecognizeResponse $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedRecognizer = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    batch_recognize_sample($formattedRecognizer);
}

createCustomClass

Creates a CustomClass.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent The project and location where this CustomClass will be created.
 *                                The expected format is `projects/{project}/locations/{location}`. Please see
 *                                {@see SpeechClient::locationName()} for help formatting this field.
 */
function create_custom_class_sample(string $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $customClass = new CustomClass();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createCustomClass($customClass, $formattedParent);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var CustomClass $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    create_custom_class_sample($formattedParent);
}

createPhraseSet

Creates a PhraseSet.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent The project and location where this PhraseSet will be created.
 *                                The expected format is `projects/{project}/locations/{location}`. Please see
 *                                {@see SpeechClient::locationName()} for help formatting this field.
 */
function create_phrase_set_sample(string $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $phraseSet = new PhraseSet();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createPhraseSet($phraseSet, $formattedParent);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var PhraseSet $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    create_phrase_set_sample($formattedParent);
}

createRecognizer

Creates a Recognizer.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $recognizerModel                Which model to use for recognition requests. Select the model
 *                                               best suited to your domain to get best results.
 *
 *                                               Guidance for choosing which model to use can be found in the [Transcription
 *                                               Models
 *                                               Documentation](https://cloud.google.com/speech-to-text/v2/docs/transcription-model)
 *                                               and the models supported in each region can be found in the [Table Of
 *                                               Supported
 *                                               Models](https://cloud.google.com/speech-to-text/v2/docs/speech-to-text-supported-languages).
 * @param string $recognizerLanguageCodesElement The language of the supplied audio as a
 *                                               [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag.
 *
 *                                               Supported languages for each model are listed in the [Table of Supported
 *                                               Models](https://cloud.google.com/speech-to-text/v2/docs/speech-to-text-supported-languages).
 *
 *                                               If additional languages are provided, recognition result will contain
 *                                               recognition in the most likely language detected. The recognition result
 *                                               will include the language tag of the language detected in the audio.
 *                                               When you create or update a Recognizer, these values are
 *                                               stored in normalized BCP-47 form. For example, "en-us" is stored as
 *                                               "en-US".
 * @param string $formattedParent                The project and location where this Recognizer will be created.
 *                                               The expected format is `projects/{project}/locations/{location}`. Please see
 *                                               {@see SpeechClient::locationName()} for help formatting this field.
 */
function create_recognizer_sample(
    string $recognizerModel,
    string $recognizerLanguageCodesElement,
    string $formattedParent
): void {
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $recognizerLanguageCodes = [$recognizerLanguageCodesElement,];
    $recognizer = (new Recognizer())
        ->setModel($recognizerModel)
        ->setLanguageCodes($recognizerLanguageCodes);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createRecognizer($recognizer, $formattedParent);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Recognizer $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $recognizerModel = '[MODEL]';
    $recognizerLanguageCodesElement = '[LANGUAGE_CODES]';
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    create_recognizer_sample($recognizerModel, $recognizerLanguageCodesElement, $formattedParent);
}

deleteCustomClass

Deletes the CustomClass.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the CustomClass to delete.
 *                              Format:
 *                              `projects/{project}/locations/{location}/customClasses/{custom_class}`
 *                              Please see {@see SpeechClient::customClassName()} for help formatting this field.
 */
function delete_custom_class_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deleteCustomClass($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var CustomClass $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');

    delete_custom_class_sample($formattedName);
}

deletePhraseSet

Deletes the PhraseSet.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the PhraseSet to delete.
 *                              Format: `projects/{project}/locations/{location}/phraseSets/{phrase_set}`
 *                              Please see {@see SpeechClient::phraseSetName()} for help formatting this field.
 */
function delete_phrase_set_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deletePhraseSet($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var PhraseSet $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');

    delete_phrase_set_sample($formattedName);
}

deleteRecognizer

Deletes the Recognizer.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the Recognizer to delete.
 *                              Format: `projects/{project}/locations/{location}/recognizers/{recognizer}`
 *                              Please see {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function delete_recognizer_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deleteRecognizer($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Recognizer $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    delete_recognizer_sample($formattedName);
}

getConfig

Returns the requested Config.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\Config
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedName 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`. Please see
 *                              {@see SpeechClient::configName()} for help formatting this field.
 */
function get_config_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var Config $response */
        $response = $speechClient->getConfig($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::configName('[PROJECT]', '[LOCATION]');

    get_config_sample($formattedName);
}

getCustomClass

Returns the requested CustomClass.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\CustomClass
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedName The name of the CustomClass to retrieve. The expected format is
 *                              `projects/{project}/locations/{location}/customClasses/{custom_class}`. Please see
 *                              {@see SpeechClient::customClassName()} for help formatting this field.
 */
function get_custom_class_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var CustomClass $response */
        $response = $speechClient->getCustomClass($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');

    get_custom_class_sample($formattedName);
}

getPhraseSet

Returns the requested PhraseSet.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\PhraseSet
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedName The name of the PhraseSet to retrieve. The expected format is
 *                              `projects/{project}/locations/{location}/phraseSets/{phrase_set}`. Please see
 *                              {@see SpeechClient::phraseSetName()} for help formatting this field.
 */
function get_phrase_set_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var PhraseSet $response */
        $response = $speechClient->getPhraseSet($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');

    get_phrase_set_sample($formattedName);
}

getRecognizer

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

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\Recognizer
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedName The name of the Recognizer to retrieve. The expected format is
 *                              `projects/{project}/locations/{location}/recognizers/{recognizer}`. Please see
 *                              {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function get_recognizer_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var Recognizer $response */
        $response = $speechClient->getRecognizer($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    get_recognizer_sample($formattedName);
}

listCustomClasses

Lists CustomClasses.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedParent The project and location of CustomClass resources to list. The
 *                                expected format is `projects/{project}/locations/{location}`. Please see
 *                                {@see SpeechClient::locationName()} for help formatting this field.
 */
function list_custom_classes_sample(string $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $speechClient->listCustomClasses($formattedParent);

        /** @var CustomClass $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    list_custom_classes_sample($formattedParent);
}

listPhraseSets

Lists PhraseSets.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedParent The project and location of PhraseSet resources to list. The
 *                                expected format is `projects/{project}/locations/{location}`. Please see
 *                                {@see SpeechClient::locationName()} for help formatting this field.
 */
function list_phrase_sets_sample(string $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $speechClient->listPhraseSets($formattedParent);

        /** @var PhraseSet $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    list_phrase_sets_sample($formattedParent);
}

listRecognizers

Lists Recognizers.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedParent The project and location of Recognizers to list. The expected
 *                                format is `projects/{project}/locations/{location}`. Please see
 *                                {@see SpeechClient::locationName()} for help formatting this field.
 */
function list_recognizers_sample(string $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $speechClient->listRecognizers($formattedParent);

        /** @var Recognizer $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = SpeechClient::locationName('[PROJECT]', '[LOCATION]');

    list_recognizers_sample($formattedParent);
}

recognize

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

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\RecognizeResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\RecognizeResponse;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * @param string $formattedRecognizer The name of the Recognizer to use during recognition. The
 *                                    expected format is
 *                                    `projects/{project}/locations/{location}/recognizers/{recognizer}`. Please see
 *                                    {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function recognize_sample(string $formattedRecognizer): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var RecognizeResponse $response */
        $response = $speechClient->recognize($formattedRecognizer);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedRecognizer = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    recognize_sample($formattedRecognizer);
}

streamingRecognize

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

Parameters
NameDescription
optionalArgs array

Optional.

↳ timeoutMillis int

Timeout to use for this call.

Returns
TypeDescription
Google\ApiCore\BidiStream
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Cloud\Speech\V2\StreamingRecognizeRequest;
use Google\Cloud\Speech\V2\StreamingRecognizeResponse;

/**
 * @param string $formattedRecognizer Streaming recognition should start with an initial request having
 *                                    a `recognizer`. Subsequent requests carry the audio data to be recognized.
 *
 *                                    The initial request with configuration can be omitted if the Recognizer
 *                                    being used has a
 *                                    [default_recognition_config][google.cloud.speech.v2.Recognizer.default_recognition_config]. Please see
 *                                    {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function streaming_recognize_sample(string $formattedRecognizer): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $request = (new StreamingRecognizeRequest())
        ->setRecognizer($formattedRecognizer);

    // Call the API and handle any network failures.
    try {
        /** @var BidiStream $stream */
        $stream = $speechClient->streamingRecognize();
        $stream->writeAll([$request,]);

        /** @var StreamingRecognizeResponse $element */
        foreach ($stream->closeWriteAndReadAll() as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedRecognizer = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    streaming_recognize_sample($formattedRecognizer);
}

undeleteCustomClass

Undeletes the CustomClass.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the CustomClass to undelete.
 *                              Format:
 *                              `projects/{project}/locations/{location}/customClasses/{custom_class}`
 *                              Please see {@see SpeechClient::customClassName()} for help formatting this field.
 */
function undelete_custom_class_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeleteCustomClass($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var CustomClass $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::customClassName('[PROJECT]', '[LOCATION]', '[CUSTOM_CLASS]');

    undelete_custom_class_sample($formattedName);
}

undeletePhraseSet

Undeletes the PhraseSet.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the PhraseSet to undelete.
 *                              Format: `projects/{project}/locations/{location}/phraseSets/{phrase_set}`
 *                              Please see {@see SpeechClient::phraseSetName()} for help formatting this field.
 */
function undelete_phrase_set_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeletePhraseSet($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var PhraseSet $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::phraseSetName('[PROJECT]', '[LOCATION]', '[PHRASE_SET]');

    undelete_phrase_set_sample($formattedName);
}

undeleteRecognizer

Undeletes the Recognizer.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the Recognizer to undelete.
 *                              Format: `projects/{project}/locations/{location}/recognizers/{recognizer}`
 *                              Please see {@see SpeechClient::recognizerName()} for help formatting this field.
 */
function undelete_recognizer_sample(string $formattedName): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeleteRecognizer($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Recognizer $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = SpeechClient::recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');

    undelete_recognizer_sample($formattedName);
}

updateConfig

Updates the Config.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Speech\V2\Config
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_config_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $config = new Config();

    // Call the API and handle any network failures.
    try {
        /** @var Config $response */
        $response = $speechClient->updateConfig($config);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateCustomClass

Updates the CustomClass.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_custom_class_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $customClass = new CustomClass();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updateCustomClass($customClass);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var CustomClass $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updatePhraseSet

Updates the PhraseSet.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_phrase_set_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $phraseSet = new PhraseSet();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updatePhraseSet($phraseSet);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var PhraseSet $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateRecognizer

Updates the Recognizer.

Parameters
NameDescription
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 Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;

/**
 * @param string $recognizerModel                Which model to use for recognition requests. Select the model
 *                                               best suited to your domain to get best results.
 *
 *                                               Guidance for choosing which model to use can be found in the [Transcription
 *                                               Models
 *                                               Documentation](https://cloud.google.com/speech-to-text/v2/docs/transcription-model)
 *                                               and the models supported in each region can be found in the [Table Of
 *                                               Supported
 *                                               Models](https://cloud.google.com/speech-to-text/v2/docs/speech-to-text-supported-languages).
 * @param string $recognizerLanguageCodesElement The language of the supplied audio as a
 *                                               [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag.
 *
 *                                               Supported languages for each model are listed in the [Table of Supported
 *                                               Models](https://cloud.google.com/speech-to-text/v2/docs/speech-to-text-supported-languages).
 *
 *                                               If additional languages are provided, recognition result will contain
 *                                               recognition in the most likely language detected. The recognition result
 *                                               will include the language tag of the language detected in the audio.
 *                                               When you create or update a Recognizer, these values are
 *                                               stored in normalized BCP-47 form. For example, "en-us" is stored as
 *                                               "en-US".
 */
function update_recognizer_sample(
    string $recognizerModel,
    string $recognizerLanguageCodesElement
): void {
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $recognizerLanguageCodes = [$recognizerLanguageCodesElement,];
    $recognizer = (new Recognizer())
        ->setModel($recognizerModel)
        ->setLanguageCodes($recognizerLanguageCodes);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updateRecognizer($recognizer);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Recognizer $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $recognizerModel = '[MODEL]';
    $recognizerLanguageCodesElement = '[LANGUAGE_CODES]';

    update_recognizer_sample($recognizerModel, $recognizerLanguageCodesElement);
}

getLocation

Gets information about a location.

Parameters
NameDescription
optionalArgs array

Optional.

↳ name string

Resource name for the location.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Location\Location
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function get_location_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var Location $response */
        $response = $speechClient->getLocation();
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

listLocations

Lists information about the supported locations for this service.

Parameters
NameDescription
optionalArgs array

Optional.

↳ name string

The resource that owns the locations collection, if applicable.

↳ filter string

The standard list filter.

↳ 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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\SpeechClient;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function list_locations_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $speechClient->listLocations();

        /** @var Location $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

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.