Cloud Speech V2 Client - Class SpeechClient (1.19.1)

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.

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.

Namespace

Google \ Cloud \ Speech \ V2 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
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.

The async variant is SpeechClient::batchRecognizeAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\BatchRecognizeRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\BatchRecognizeRequest;
use Google\Cloud\Speech\V2\BatchRecognizeResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Rpc\Status;

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

    // Prepare the request message.
    $request = (new BatchRecognizeRequest())
        ->setRecognizer($formattedRecognizer);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->batchRecognize($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::createCustomClassAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\CreateCustomClassRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CreateCustomClassRequest;
use Google\Cloud\Speech\V2\CustomClass;
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 the request message.
    $customClass = new CustomClass();
    $request = (new CreateCustomClassRequest())
        ->setCustomClass($customClass)
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createCustomClass($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::createPhraseSetAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\CreatePhraseSetRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CreatePhraseSetRequest;
use Google\Cloud\Speech\V2\PhraseSet;
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 the request message.
    $phraseSet = new PhraseSet();
    $request = (new CreatePhraseSetRequest())
        ->setPhraseSet($phraseSet)
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createPhraseSet($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::createRecognizerAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\CreateRecognizerRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CreateRecognizerRequest;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Rpc\Status;

/**
 * @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 $formattedParent): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare the request message.
    $recognizer = new Recognizer();
    $request = (new CreateRecognizerRequest())
        ->setRecognizer($recognizer)
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->createRecognizer($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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_recognizer_sample($formattedParent);
}

deleteCustomClass

Deletes the CustomClass.

The async variant is SpeechClient::deleteCustomClassAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\DeleteCustomClassRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\DeleteCustomClassRequest;
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();

    // Prepare the request message.
    $request = (new DeleteCustomClassRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deleteCustomClass($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::deletePhraseSetAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\DeletePhraseSetRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\DeletePhraseSetRequest;
use Google\Cloud\Speech\V2\PhraseSet;
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();

    // Prepare the request message.
    $request = (new DeletePhraseSetRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deletePhraseSet($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::deleteRecognizerAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\DeleteRecognizerRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\DeleteRecognizerRequest;
use Google\Cloud\Speech\V2\Recognizer;
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();

    // Prepare the request message.
    $request = (new DeleteRecognizerRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->deleteRecognizer($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::getConfigAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\GetConfigRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\Config
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\GetConfigRequest;

/**
 * @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();

    // Prepare the request message.
    $request = (new GetConfigRequest())
        ->setName($formattedName);

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::getCustomClassAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\GetCustomClassRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\CustomClass
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\GetCustomClassRequest;

/**
 * @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();

    // Prepare the request message.
    $request = (new GetCustomClassRequest())
        ->setName($formattedName);

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::getPhraseSetAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\GetPhraseSetRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\PhraseSet
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\GetPhraseSetRequest;
use Google\Cloud\Speech\V2\PhraseSet;

/**
 * @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();

    // Prepare the request message.
    $request = (new GetPhraseSetRequest())
        ->setName($formattedName);

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::getRecognizerAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\GetRecognizerRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\Recognizer
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\GetRecognizerRequest;
use Google\Cloud\Speech\V2\Recognizer;

/**
 * @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();

    // Prepare the request message.
    $request = (new GetRecognizerRequest())
        ->setName($formattedName);

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::listCustomClassesAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\ListCustomClassesRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\ListCustomClassesRequest;

/**
 * @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();

    // Prepare the request message.
    $request = (new ListCustomClassesRequest())
        ->setParent($formattedParent);

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

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::listPhraseSetsAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\ListPhraseSetsRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\ListPhraseSetsRequest;
use Google\Cloud\Speech\V2\PhraseSet;

/**
 * @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();

    // Prepare the request message.
    $request = (new ListPhraseSetsRequest())
        ->setParent($formattedParent);

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

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::listRecognizersAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\ListRecognizersRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\ListRecognizersRequest;
use Google\Cloud\Speech\V2\Recognizer;

/**
 * @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();

    // Prepare the request message.
    $request = (new ListRecognizersRequest())
        ->setParent($formattedParent);

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

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

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::recognizeAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\RecognizeRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\RecognizeResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\RecognizeRequest;
use Google\Cloud\Speech\V2\RecognizeResponse;

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

    // Prepare the request message.
    $request = (new RecognizeRequest())
        ->setRecognizer($formattedRecognizer);

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

/**
 * Helper to execute the sample.
 *
 * 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
Name Description
callOptions array

Optional.

↳ timeoutMillis int

Timeout to use for this call.

Returns
Type Description
Google\ApiCore\BidiStream
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\StreamingRecognizeRequest;
use Google\Cloud\Speech\V2\StreamingRecognizeResponse;

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

    // Prepare the request message.
    $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::undeleteCustomClassAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeleteCustomClassRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\UndeleteCustomClassRequest;
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();

    // Prepare the request message.
    $request = (new UndeleteCustomClassRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeleteCustomClass($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::undeletePhraseSetAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeletePhraseSetRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\UndeletePhraseSetRequest;
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();

    // Prepare the request message.
    $request = (new UndeletePhraseSetRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeletePhraseSet($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::undeleteRecognizerAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeleteRecognizerRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\UndeleteRecognizerRequest;
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();

    // Prepare the request message.
    $request = (new UndeleteRecognizerRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->undeleteRecognizer($request);
        $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());
    }
}

/**
 * Helper to execute the sample.
 *
 * 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.

The async variant is SpeechClient::updateConfigAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateConfigRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Speech\V2\Config
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\UpdateConfigRequest;

/**
 * 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 the request message.
    $config = new Config();
    $request = (new UpdateConfigRequest())
        ->setConfig($config);

    // Call the API and handle any network failures.
    try {
        /** @var Config $response */
        $response = $speechClient->updateConfig($request);
        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.

The async variant is SpeechClient::updateCustomClassAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateCustomClassRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\UpdateCustomClassRequest;
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 the request message.
    $customClass = new CustomClass();
    $request = (new UpdateCustomClassRequest())
        ->setCustomClass($customClass);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updateCustomClass($request);
        $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.

The async variant is SpeechClient::updatePhraseSetAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdatePhraseSetRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\UpdatePhraseSetRequest;
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 the request message.
    $phraseSet = new PhraseSet();
    $request = (new UpdatePhraseSetRequest())
        ->setPhraseSet($phraseSet);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updatePhraseSet($request);
        $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.

The async variant is SpeechClient::updateRecognizerAsync() .

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateRecognizerRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Client\SpeechClient;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\UpdateRecognizerRequest;
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_recognizer_sample(): void
{
    // Create a client.
    $speechClient = new SpeechClient();

    // Prepare the request message.
    $recognizer = new Recognizer();
    $request = (new UpdateRecognizerRequest())
        ->setRecognizer($recognizer);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $speechClient->updateRecognizer($request);
        $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());
    }
}

getLocation

Gets information about a location.

The async variant is SpeechClient::getLocationAsync() .

Parameters
Name Description
request Google\Cloud\Location\GetLocationRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\Cloud\Location\Location
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\Client\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();

    // Prepare the request message.
    $request = new GetLocationRequest();

    // Call the API and handle any network failures.
    try {
        /** @var Location $response */
        $response = $speechClient->getLocation($request);
        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.

The async variant is SpeechClient::listLocationsAsync() .

Parameters
Name Description
request Google\Cloud\Location\ListLocationsRequest

A request to house fields associated with the call.

callOptions 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
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\Client\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();

    // Prepare the request message.
    $request = new ListLocationsRequest();

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

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

batchRecognizeAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\BatchRecognizeRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

createCustomClassAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\CreateCustomClassRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

createPhraseSetAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\CreatePhraseSetRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

createRecognizerAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\CreateRecognizerRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

deleteCustomClassAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\DeleteCustomClassRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

deletePhraseSetAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\DeletePhraseSetRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

deleteRecognizerAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\DeleteRecognizerRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

getConfigAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\GetConfigRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\Config>

getCustomClassAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\GetCustomClassRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\CustomClass>

getPhraseSetAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\GetPhraseSetRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\PhraseSet>

getRecognizerAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\GetRecognizerRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\Recognizer>

listCustomClassesAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\ListCustomClassesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

listPhraseSetsAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\ListPhraseSetsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

listRecognizersAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\ListRecognizersRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

recognizeAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\RecognizeRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\RecognizeResponse>

undeleteCustomClassAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeleteCustomClassRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

undeletePhraseSetAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeletePhraseSetRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

undeleteRecognizerAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UndeleteRecognizerRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

updateConfigAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateConfigRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Speech\V2\Config>

updateCustomClassAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateCustomClassRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

updatePhraseSetAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdatePhraseSetRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

updateRecognizerAsync

Parameters
Name Description
request Google\Cloud\Speech\V2\UpdateRecognizerRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\OperationResponse>

getLocationAsync

Parameters
Name Description
request Google\Cloud\Location\GetLocationRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Location\Location>

listLocationsAsync

Parameters
Name Description
request Google\Cloud\Location\ListLocationsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

getOperationsClient

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

Returns
Type Description
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
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
Google\ApiCore\OperationResponse

static::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.

static::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.

static::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.

static::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.

static::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.

static::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.

static::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.

static::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.