Skip to content

Commit b11f89d

Browse files
authored
Add speech 1.1 and gcs (GoogleCloudPlatform#345)
* defaults logger sample to the last 24 hours * Updates for Speech 1.1 and Cloud Storage integration * removes async_recognize, speech v1 now requires gcs uri
1 parent 60babcf commit b11f89d

File tree

9 files changed

+244
-83
lines changed

9 files changed

+244
-83
lines changed

logging/api/src/ListEntriesCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
4343
$entries = list_entries($projectId, $loggerName);
4444
foreach ($entries as $entry) {
4545
/* @var $entry \Google\Cloud\Logging\Entry */
46+
$entryInfo = $entry->info();
47+
if (isset($entryInfo['textPayload'])) {
48+
$entryText = $entryInfo['textPayload'];
49+
} else {
50+
$entryText = $this->formatJsonPayload($entryInfo['jsonPayload']);
51+
}
4652
printf(
4753
"%s : %s" . PHP_EOL,
48-
$entry->info()['timestamp'],
49-
$entry->info()['textPayload']
54+
$entryInfo['timestamp'],
55+
$entryText
5056
);
5157
}
5258
}
59+
60+
private function formatJsonPayload(array $jsonPayload)
61+
{
62+
$entryPayload = [];
63+
foreach ($jsonPayload as $key => $value) {
64+
$entryPayload[] = "$key=$value";
65+
}
66+
return '{' . implode(', ', $entryPayload) . '}';
67+
}
5368
}

logging/api/src/functions/log_entry_functions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ function list_entries($projectId, $loggerName)
5757
{
5858
$logging = new LoggingClient(['projectId' => $projectId]);
5959
$loggerFullName = sprintf('projects/%s/logs/%s', $projectId, $loggerName);
60+
$oneDayAgo = date(\DateTime::RFC3339, strtotime('-24 hours'));
61+
$filter = sprintf(
62+
'logName = "%s" AND timestamp >= "%s"',
63+
$loggerFullName,
64+
$oneDayAgo
65+
);
6066
$options = [
61-
'filter' => sprintf('logName = "%s"', $loggerFullName)
67+
'filter' => $filter,
6268
];
6369
return $logging->entries($options);
6470
}

speech/api/composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"require": {
33
"google/cloud-speech": "^0.2",
4+
"google/cloud-storage": "^1.0",
45
"symfony/console": "^3.0"
56
},
67
"autoload": {
78
"psr-4": {
89
"Google\\Cloud\\Samples\\Speech\\": "src/"
910
},
1011
"files": [
11-
"src/functions/transcribe_async.php",
12-
"src/functions/transcribe_sync.php"
12+
"src/functions/transcribe_async_gcs.php",
13+
"src/functions/transcribe_sync.php",
14+
"src/functions/transcribe_sync_gcs.php"
1315
]
1416
},
1517
"require-dev": {

0 commit comments

Comments
 (0)