Skip to content

Commit f8cf45d

Browse files
committed
feat(Speech): add list recognizers sample
1 parent 750985c commit f8cf45d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

speech/src/list_recognizers.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\Cloud\Samples\Speech;
19+
20+
use Google\Cloud\Speech\V2\Client\SpeechClient;
21+
use Google\Cloud\Speech\V2\ListRecognizersRequest;
22+
use Google\Cloud\Speech\V2\Recognizer;
23+
24+
/**
25+
* List all recognizers.
26+
*
27+
* @param string $projectId The Google Cloud project ID.
28+
* @param string $location The location of the recognizer.
29+
*/
30+
function list_recognizers(
31+
string $projectId,
32+
string $location,
33+
): void {
34+
$apiEndpoint = $location === 'global' ? null : sprintf('%s-speech.googleapis.com', $location);
35+
$speech = new SpeechClient(['apiEndpoint' => $apiEndpoint]);
36+
37+
// Create the ListRecognizersRequest
38+
$ListRecognizersRequest = new ListRecognizersRequest([
39+
'parent' => SpeechClient::locationName($projectId, $location),
40+
]);
41+
42+
// Call the ListRecognizers method
43+
$responses = $speech->listRecognizers($ListRecognizersRequest);
44+
45+
foreach ($responses as $recognizer) {
46+
printf('Recognizer name: %s' . PHP_EOL, $recognizer->getName());
47+
}
48+
}
49+
50+
// The following 2 lines are only needed to run the samples
51+
require_once __DIR__ . '/../../testing/sample_helpers.php';
52+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)