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 \ ClientMethods
__construct
Constructor.
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. Important : If you accept a credential configuration (credential JSON/File/Stream) from an external source for authentication to Google Cloud Platform, you must validate it before providing it to any Google API or library. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. For more information https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
↳ 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.
↳ logger
false|LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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).
callOptions
array
Optional.
↳ timeoutMillis
int
Timeout to use for this call.
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() .
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.
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() .
request
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.
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() .
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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() .
request
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.
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
createCustomClassAsync
optionalArgs
array
createPhraseSetAsync
optionalArgs
array
createRecognizerAsync
optionalArgs
array
deleteCustomClassAsync
optionalArgs
array
deletePhraseSetAsync
optionalArgs
array
deleteRecognizerAsync
optionalArgs
array
getConfigAsync
getCustomClassAsync
getPhraseSetAsync
getRecognizerAsync
listCustomClassesAsync
optionalArgs
array
listPhraseSetsAsync
listRecognizersAsync
optionalArgs
array
recognizeAsync
undeleteCustomClassAsync
optionalArgs
array
undeletePhraseSetAsync
optionalArgs
array
undeleteRecognizerAsync
optionalArgs
array
updateConfigAsync
updateCustomClassAsync
optionalArgs
array
updatePhraseSetAsync
optionalArgs
array
updateRecognizerAsync
optionalArgs
array
getLocationAsync
listLocationsAsync
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Google\LongRunning\Client\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.
operationName
string
The name of the long running operation
methodName
string
The name of the method used to start the operation
static::configName
Formats a string containing the fully-qualified path to represent a config resource.
project
string
location
string
string
static::cryptoKeyName
Formats a string containing the fully-qualified path to represent a crypto_key resource.
project
string
location
string
keyRing
string
cryptoKey
string
string
static::cryptoKeyVersionName
Formats a string containing the fully-qualified path to represent a crypto_key_version resource.
project
string
location
string
keyRing
string
cryptoKey
string
cryptoKeyVersion
string
string
static::customClassName
Formats a string containing the fully-qualified path to represent a custom_class resource.
project
string
location
string
customClass
string
string
static::locationName
Formats a string containing the fully-qualified path to represent a location resource.
project
string
location
string
string
static::phraseSetName
Formats a string containing the fully-qualified path to represent a phrase_set resource.
project
string
location
string
phraseSet
string
string
static::recognizerName
Formats a string containing the fully-qualified path to represent a recognizer resource.
project
string
location
string
recognizer
string
string
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.
formattedName
string
The formatted name string
template
?string
Optional name of template to match
array