Skip to content

Commit 9db1167

Browse files
jerjouTakashi Matsuo
authored andcommitted
Print out all results. (GoogleCloudPlatform#438)
1 parent 3d8e2fd commit 9db1167

7 files changed

+17
-14
lines changed

speech/quickstart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
# Detects speech in the audio file
4444
$results = $speech->recognize(fopen($fileName, 'r'), $options);
4545

46-
foreach ($results[0]->alternatives() as $alternative) {
47-
echo 'Transcription: ' . $alternative['transcript'] . PHP_EOL;
46+
foreach ($results as $result) {
47+
echo 'Transcription: ' . $result->alternatives()[0]['transcript'] . PHP_EOL;
4848
}
4949

5050
# [END speech_quickstart]

speech/src/transcribe_async.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ function transcribe_async($audioFile, $languageCode = 'en-US', $options = [])
6767

6868
// Print the results
6969
if ($operation->isComplete()) {
70-
$alternatives = $operation->results()[0]->alternatives();
71-
foreach ($alternatives as $alternative) {
70+
$results = $operation->results();
71+
foreach ($results as $result) {
72+
$alternative = $result->alternatives()[0];
7273
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
7374
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
7475
}

speech/src/transcribe_async_gcs.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ function transcribe_async_gcs($bucketName, $objectName, $languageCode = 'en-US',
7373

7474
// Print the results
7575
if ($operation->isComplete()) {
76-
$alternatives = $operation->results()[0]->alternatives();
77-
foreach ($alternatives as $alternative) {
76+
$results = $operation->results();
77+
foreach ($results as $result) {
78+
$alternative = $result->alternatives()[0];
7879
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
7980
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
8081
}

speech/src/transcribe_async_words.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ function transcribe_async_words($audioFile, $languageCode = 'en-US', $options =
7070

7171
// Print the results
7272
if ($operation->isComplete()) {
73-
$alternatives = $operation->results()[0]->alternatives();
74-
foreach ($alternatives as $alternative) {
73+
$results = $operation->results();
74+
foreach ($results as $result) {
75+
$alternative = $result->alternatives()[0];
7576
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
7677
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
7778
foreach ($alternative['words'] as $wordInfo) {

speech/src/transcribe_sync.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function transcribe_sync($audioFile, $languageCode = 'en-US', $options = [])
5454
);
5555

5656
// Print the results
57-
$alternatives = $results[0]->alternatives();
58-
foreach ($alternatives as $alternative) {
57+
foreach ($results as $result) {
58+
$alternative = $result->alternatives()[0];
5959
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
6060
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
6161
}

speech/src/transcribe_sync_gcs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function transcribe_sync_gcs($bucketName, $objectName, $languageCode = 'en-US',
5959
);
6060

6161
// Print the results
62-
$alternatives = $results[0]->alternatives();
63-
foreach ($alternatives as $alternative) {
62+
foreach ($results as $result) {
63+
$alternative = $result->alternatives()[0];
6464
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
6565
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
6666
}

speech/src/transcribe_sync_words.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function transcribe_sync_words($audioFile, $languageCode = 'en-US', $options = [
5757
);
5858

5959
// Print the results
60-
$alternatives = $results[0]->alternatives();
61-
foreach ($alternatives as $alternative) {
60+
foreach ($results as $result) {
61+
$alternative = $result->alternatives();
6262
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
6363
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
6464
foreach ($alternative['words'] as $wordInfo) {

0 commit comments

Comments
 (0)