Reference documentation and code samples for the Cloud Speech V2 Client class SpeechClient.
Service Description: Enables speech transcription and resource management.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$speechClient = new SpeechClient();
try {
$formattedRecognizer = $speechClient->recognizerName('[PROJECT]', '[LOCATION]', '[RECOGNIZER]');
$operationResponse = $speechClient->batchRecognize($formattedRecognizer);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $speechClient->batchRecognize($formattedRecognizer);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $speechClient->resumeOperation($operationName, 'batchRecognize');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$speechClient->close();
}
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
This service has a new (beta) implementation. See Google\Cloud\Speech\V2\Client\SpeechClient to use the new surface.
Namespace
Google \ Cloud \ Speech \ V2Methods
__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 |
↳ 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 |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
batchRecognize
Performs batch asynchronous speech recognition: send a request with N audio files and receive a long running operation that can be polled to see when the transcriptions are finished.
Parameters | |
---|---|
Name | Description |
recognizer |
string
Required. The name of the Recognizer to use during recognition. The
expected format is
|
optionalArgs |
array
Optional. |
↳ config |
RecognitionConfig
Features and audio metadata to use for the Automatic Speech Recognition. This field in combination with the config_mask field can be used to override parts of the default_recognition_config of the Recognizer resource. |
↳ configMask |
FieldMask
The list of fields in config that override the values in the default_recognition_config of the recognizer during this recognition request. If no mask is provided, all given fields in config override the values in the recognizer for this recognition request. If a mask is provided, only the fields listed in the mask override the config in the recognizer for this recognition request. If a wildcard ( |
↳ files |
BatchRecognizeFileMetadata[]
Audio files with file metadata for ASR. The maximum number of files allowed to be specified is 5. |
↳ recognitionOutputConfig |
RecognitionOutputConfig
Configuration options for where to output the transcripts of each file. |
↳ processingStrategy |
int
Processing strategy to use for this request. For allowed values, use constants defined on Google\Cloud\Speech\V2\BatchRecognizeRequest\ProcessingStrategy |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\BatchRecognizeResponse;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedRecognizer 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();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->batchRecognize($formattedRecognizer);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var BatchRecognizeResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
customClass |
Google\Cloud\Speech\V2\CustomClass
Required. The CustomClass to create. |
parent |
string
Required. The project and location where this CustomClass will be created.
The expected format is |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the CustomClass, but do not actually create it. |
↳ customClassId |
string
The ID to use for the CustomClass, which will become the final component of the CustomClass's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedParent The project and location where this CustomClass will be created.
* The expected format is `projects/{project}/locations/{location}`. Please see
* {@see SpeechClient::locationName()} for help formatting this field.
*/
function create_custom_class_sample(string $formattedParent): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$customClass = new CustomClass();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->createCustomClass($customClass, $formattedParent);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var CustomClass $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
phraseSet |
Google\Cloud\Speech\V2\PhraseSet
Required. The PhraseSet to create. |
parent |
string
Required. The project and location where this PhraseSet will be created.
The expected format is |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the PhraseSet, but do not actually create it. |
↳ phraseSetId |
string
The ID to use for the PhraseSet, which will become the final component of the PhraseSet's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedParent The project and location where this PhraseSet will be created.
* The expected format is `projects/{project}/locations/{location}`. Please see
* {@see SpeechClient::locationName()} for help formatting this field.
*/
function create_phrase_set_sample(string $formattedParent): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$phraseSet = new PhraseSet();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->createPhraseSet($phraseSet, $formattedParent);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var PhraseSet $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
recognizer |
Google\Cloud\Speech\V2\Recognizer
Required. The Recognizer to create. |
parent |
string
Required. The project and location where this Recognizer will be created.
The expected format is |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the Recognizer, but do not actually create it. |
↳ recognizerId |
string
The ID to use for the Recognizer, which will become the final component of the Recognizer's resource name. This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $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 any non-scalar elements to be passed along with the request.
$recognizer = new Recognizer();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->createRecognizer($recognizer, $formattedParent);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Recognizer $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the CustomClass to delete.
Format:
|
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the deleted CustomClass, but do not actually delete it. |
↳ allowMissing |
bool
If set to true, and the CustomClass is not found, the request will succeed and be a no-op (no Operation is recorded in this case). |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the CustomClass to delete.
* Format:
* `projects/{project}/locations/{location}/customClasses/{custom_class}`
* Please see {@see SpeechClient::customClassName()} for help formatting this field.
*/
function delete_custom_class_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->deleteCustomClass($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var CustomClass $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the PhraseSet to delete.
Format: |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the deleted PhraseSet, but do not actually delete it. |
↳ allowMissing |
bool
If set to true, and the PhraseSet is not found, the request will succeed and be a no-op (no Operation is recorded in this case). |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the PhraseSet to delete.
* Format: `projects/{project}/locations/{location}/phraseSets/{phrase_set}`
* Please see {@see SpeechClient::phraseSetName()} for help formatting this field.
*/
function delete_phrase_set_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->deletePhraseSet($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var PhraseSet $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the Recognizer to delete.
Format: |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the deleted Recognizer, but do not actually delete it. |
↳ allowMissing |
bool
If set to true, and the Recognizer is not found, the request will succeed and be a no-op (no Operation is recorded in this case). |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the Recognizer to delete.
* Format: `projects/{project}/locations/{location}/recognizers/{recognizer}`
* Please see {@see SpeechClient::recognizerName()} for help formatting this field.
*/
function delete_recognizer_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->deleteRecognizer($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Recognizer $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the config to retrieve. There is exactly one config
resource per project per location. The expected format is
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Speech\V2\Config |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedName The name of the config to retrieve. There is exactly one config
* resource per project per location. The expected format is
* `projects/{project}/locations/{location}/config`. Please see
* {@see SpeechClient::configName()} for help formatting this field.
*/
function get_config_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var Config $response */
$response = $speechClient->getConfig($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the CustomClass to retrieve. The expected format is
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Speech\V2\CustomClass |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedName The name of the CustomClass to retrieve. The expected format is
* `projects/{project}/locations/{location}/customClasses/{custom_class}`. Please see
* {@see SpeechClient::customClassName()} for help formatting this field.
*/
function get_custom_class_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var CustomClass $response */
$response = $speechClient->getCustomClass($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the PhraseSet to retrieve. The expected format is
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Speech\V2\PhraseSet |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedName The name of the PhraseSet to retrieve. The expected format is
* `projects/{project}/locations/{location}/phraseSets/{phrase_set}`. Please see
* {@see SpeechClient::phraseSetName()} for help formatting this field.
*/
function get_phrase_set_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var PhraseSet $response */
$response = $speechClient->getPhraseSet($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the Recognizer to retrieve. The expected format is
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Speech\V2\Recognizer |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedName The name of the Recognizer to retrieve. The expected format is
* `projects/{project}/locations/{location}/recognizers/{recognizer}`. Please see
* {@see SpeechClient::recognizerName()} for help formatting this field.
*/
function get_recognizer_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var Recognizer $response */
$response = $speechClient->getRecognizer($formattedName);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The project and location of CustomClass resources to list. The
expected format is |
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ showDeleted |
bool
Whether, or not, to show resources that have been deleted. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedParent The project and location of CustomClass resources to list. The
* expected format is `projects/{project}/locations/{location}`. Please see
* {@see SpeechClient::locationName()} for help formatting this field.
*/
function list_custom_classes_sample(string $formattedParent): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $speechClient->listCustomClasses($formattedParent);
/** @var CustomClass $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The project and location of PhraseSet resources to list. The
expected format is |
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ showDeleted |
bool
Whether, or not, to show resources that have been deleted. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedParent The project and location of PhraseSet resources to list. The
* expected format is `projects/{project}/locations/{location}`. Please see
* {@see SpeechClient::locationName()} for help formatting this field.
*/
function list_phrase_sets_sample(string $formattedParent): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $speechClient->listPhraseSets($formattedParent);
/** @var PhraseSet $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The project and location of Recognizers to list. The expected
format is |
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ showDeleted |
bool
Whether, or not, to show resources that have been deleted. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedParent The project and location of Recognizers to list. The expected
* format is `projects/{project}/locations/{location}`. Please see
* {@see SpeechClient::locationName()} for help formatting this field.
*/
function list_recognizers_sample(string $formattedParent): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $speechClient->listRecognizers($formattedParent);
/** @var Recognizer $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
recognizer |
string
Required. The name of the Recognizer to use during recognition. The
expected format is
|
optionalArgs |
array
Optional. |
↳ config |
RecognitionConfig
Features and audio metadata to use for the Automatic Speech Recognition. This field in combination with the config_mask field can be used to override parts of the default_recognition_config of the Recognizer resource. |
↳ configMask |
FieldMask
The list of fields in config that override the values in the default_recognition_config of the recognizer during this recognition request. If no mask is provided, all non-default valued fields in config override the values in the recognizer for this recognition request. If a mask is provided, only the fields listed in the mask override the config in the recognizer for this recognition request. If a wildcard ( |
↳ content |
string
The audio data bytes encoded as specified in RecognitionConfig. As with all bytes fields, proto buffers use a pure binary representation, whereas JSON representations use base64. |
↳ uri |
string
URI that points to a file that contains audio data bytes as specified in RecognitionConfig. The file must not be compressed (for example, gzip). Currently, only Google Cloud Storage URIs are supported, which must be specified in the following format: |
↳ 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 |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\RecognizeResponse;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* @param string $formattedRecognizer The name of the Recognizer to use during recognition. The
* expected format is
* `projects/{project}/locations/{location}/recognizers/{recognizer}`. 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();
// Call the API and handle any network failures.
try {
/** @var RecognizeResponse $response */
$response = $speechClient->recognize($formattedRecognizer);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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 |
optionalArgs |
array
Optional. |
↳ timeoutMillis |
int
Timeout to use for this call. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\BidiStream |
use Google\ApiCore\ApiException;
use Google\ApiCore\BidiStream;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Cloud\Speech\V2\StreamingRecognizeRequest;
use Google\Cloud\Speech\V2\StreamingRecognizeResponse;
/**
* @param string $formattedRecognizer 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 any non-scalar elements to be passed along with the request.
$request = (new StreamingRecognizeRequest())
->setRecognizer($formattedRecognizer);
// Call the API and handle any network failures.
try {
/** @var BidiStream $stream */
$stream = $speechClient->streamingRecognize();
$stream->writeAll([$request,]);
/** @var StreamingRecognizeResponse $element */
foreach ($stream->closeWriteAndReadAll() as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the CustomClass to undelete.
Format:
|
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the undeleted CustomClass, but do not actually undelete it. |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the CustomClass to undelete.
* Format:
* `projects/{project}/locations/{location}/customClasses/{custom_class}`
* Please see {@see SpeechClient::customClassName()} for help formatting this field.
*/
function undelete_custom_class_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->undeleteCustomClass($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var CustomClass $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the PhraseSet to undelete.
Format: |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the undeleted PhraseSet, but do not actually undelete it. |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the PhraseSet to undelete.
* Format: `projects/{project}/locations/{location}/phraseSets/{phrase_set}`
* Please see {@see SpeechClient::phraseSetName()} for help formatting this field.
*/
function undelete_phrase_set_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->undeletePhraseSet($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var PhraseSet $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the Recognizer to undelete.
Format: |
optionalArgs |
array
Optional. |
↳ validateOnly |
bool
If set, validate the request and preview the undeleted Recognizer, but do not actually undelete it. |
↳ etag |
string
This checksum is computed by the server based on the value of other fields. This may be sent on update, undelete, and delete requests to ensure the client has an up-to-date value before proceeding. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* @param string $formattedName The name of the Recognizer to undelete.
* Format: `projects/{project}/locations/{location}/recognizers/{recognizer}`
* Please see {@see SpeechClient::recognizerName()} for help formatting this field.
*/
function undelete_recognizer_sample(string $formattedName): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->undeleteRecognizer($formattedName);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Recognizer $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* 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.
Parameters | |
---|---|
Name | Description |
config |
Google\Cloud\Speech\V2\Config
Required. The config to update. The config's |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
The list of fields to be updated. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Speech\V2\Config |
use Google\ApiCore\ApiException;
use Google\Cloud\Speech\V2\Config;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_config_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$config = new Config();
// Call the API and handle any network failures.
try {
/** @var Config $response */
$response = $speechClient->updateConfig($config);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
updateCustomClass
Updates the CustomClass.
Parameters | |
---|---|
Name | Description |
customClass |
Google\Cloud\Speech\V2\CustomClass
Required. The CustomClass to update. The CustomClass's |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
The list of fields to be updated. If empty, all fields are considered for update. |
↳ validateOnly |
bool
If set, validate the request and preview the updated CustomClass, but do not actually update it. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\CustomClass;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_custom_class_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$customClass = new CustomClass();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->updateCustomClass($customClass);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var CustomClass $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
updatePhraseSet
Updates the PhraseSet.
Parameters | |
---|---|
Name | Description |
phraseSet |
Google\Cloud\Speech\V2\PhraseSet
Required. The PhraseSet to update. The PhraseSet's |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
The list of fields to update. If empty, all non-default valued fields are considered for update. Use |
↳ validateOnly |
bool
If set, validate the request and preview the updated PhraseSet, but do not actually update it. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\PhraseSet;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_phrase_set_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$phraseSet = new PhraseSet();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->updatePhraseSet($phraseSet);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var PhraseSet $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
updateRecognizer
Updates the Recognizer.
Parameters | |
---|---|
Name | Description |
recognizer |
Google\Cloud\Speech\V2\Recognizer
Required. The Recognizer to update. The Recognizer's |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
The list of fields to update. If empty, all non-default valued fields are considered for update. Use |
↳ validateOnly |
bool
If set, validate the request and preview the updated Recognizer, but do not actually update it. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Speech\V2\Recognizer;
use Google\Cloud\Speech\V2\SpeechClient;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function update_recognizer_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Prepare any non-scalar elements to be passed along with the request.
$recognizer = new Recognizer();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $speechClient->updateRecognizer($recognizer);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Recognizer $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
getLocation
Gets information about a location.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
Resource name for the location. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Location\Location |
use Google\ApiCore\ApiException;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function get_location_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $speechClient->getLocation();
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
listLocations
Lists information about the supported locations for this service.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ name |
string
The resource that owns the locations collection, if applicable. |
↳ filter |
string
The standard list filter. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\Location;
use Google\Cloud\Speech\V2\SpeechClient;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function list_locations_sample(): void
{
// Create a client.
$speechClient = new SpeechClient();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $speechClient->listLocations();
/** @var Location $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
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. |
Constants
SERVICE_NAME
Value: 'google.cloud.speech.v2.Speech'
The name of the service.
SERVICE_ADDRESS
Value: 'speech.googleapis.com'
The default address of the service.
DEFAULT_SERVICE_PORT
Value: 443
The default port of the service.
CODEGEN_NAME
Value: 'gapic'
The name of the code generator, to be included in the agent header.