Skip to content

Commit 76186e4

Browse files
authored
Remove "Project ID" from Speech Veneer Samples (GoogleCloudPlatform#162)
1 parent efd78b3 commit 76186e4

File tree

6 files changed

+11
-68
lines changed

6 files changed

+11
-68
lines changed

speech/api/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Install the dependencies for this library via [composer](https://getcomposer.org
1616
$ cd /path/to/php-docs-samples/speech/api
1717
$ composer install
1818

19-
Configure your project using [gcloud](https://cloud.google.com/sdk/gcloud/)
19+
Configure your project using [Application Default Credentials][adc]
2020

21-
$ gcloud config set project YOUR_PROJECT_ID
21+
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
2222

2323
## Audio Format
2424

@@ -44,3 +44,4 @@ php speech.php transcribe YourAudio.raw --encoding LINEAR16 --sample-rate 16000
4444
[choose-encoding]: https://cloud.google.com/speech/docs/best-practices#choosing_an_audio_encoding
4545
[sox]: http://sox.sourceforge.net/
4646
[grpc]: http://grpc.io
47+
[adc]: https://developers.google.com/identity/protocols/application-default-credentials

speech/api/src/ProjectIdTrait.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

speech/api/src/TranscribeCommand.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
*/
3131
class TranscribeCommand extends Command
3232
{
33-
use ProjectIdTrait;
34-
3533
protected function configure()
3634
{
3735
$this
@@ -49,13 +47,6 @@ protected function configure()
4947
InputArgument::REQUIRED,
5048
'The audio file to transcribe'
5149
)
52-
->addOption(
53-
'project',
54-
null,
55-
InputOption::VALUE_REQUIRED,
56-
'The Google Cloud Platform project name to use for this invocation. ' .
57-
'If omitted then the current gcloud project is assumed. '
58-
)
5950
->addOption(
6051
'encoding',
6152
null,
@@ -81,9 +72,6 @@ protected function configure()
8172

8273
protected function execute(InputInterface $input, OutputInterface $output)
8374
{
84-
if (!$projectId = $input->getOption('project')) {
85-
$projectId = $this->getProjectIdFromGcloud();
86-
}
8775
$encoding = $input->getOption('encoding');
8876
$sampleRate = $input->getOption('sample-rate');
8977
$audioFile = $input->getArgument('audio-file');
@@ -93,9 +81,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9381
];
9482

9583
if ($input->getOption('sync')) {
96-
transcribe_sync($projectId, $audioFile, $options);
84+
transcribe_sync($audioFile, $options);
9785
} else {
98-
transcribe_async($projectId, $audioFile, $options);
86+
transcribe_async($audioFile, $options);
9987
}
10088
}
10189
}

speech/api/src/functions/transcribe_async.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
3232
* Transcribe an audio file using Google Cloud Speech API
3333
* Example:
3434
* ```
35-
* transcribe_async($projectId, '/path/to/audiofile.wav');
35+
* transcribe_async('/path/to/audiofile.wav');
3636
* ```.
3737
*
38-
* @param string $projectId The Google project ID.
3938
* @param string $audioFile path to an audio file.
4039
*
4140
* @return string the text transcription
4241
*/
43-
function transcribe_async($projectId, $audioFile, $options = [])
42+
function transcribe_async($audioFile, $options = [])
4443
{
45-
$builder = new ServiceBuilder([
46-
'projectId' => $projectId,
47-
]);
44+
$builder = new ServiceBuilder();
4845
$speech = $builder->speech();
4946
$operation = $speech->beginRecognizeOperation(
5047
fopen($audioFile, 'r'),

speech/api/src/functions/transcribe_sync.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,16 @@
3030
* Transcribe an audio file using Google Cloud Speech API
3131
* Example:
3232
* ```
33-
* transcribe_sync($projectId, '/path/to/audiofile.wav');
33+
* transcribe_sync('/path/to/audiofile.wav');
3434
* ```.
3535
*
36-
* @param string $projectId The Google project ID.
3736
* @param string $audioFile path to an audio file.
3837
*
3938
* @return string the text transcription
4039
*/
41-
function transcribe_sync($projectId, $audioFile, $options = [])
40+
function transcribe_sync($audioFile, $options = [])
4241
{
43-
$builder = new ServiceBuilder([
44-
'projectId' => $projectId,
45-
]);
42+
$builder = new ServiceBuilder();
4643
$speech = $builder->speech();
4744
$results = $speech->recognize(
4845
fopen($audioFile, 'r'),

speech/api/test/TranscribeCommandTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public function testTranscribe($audioFile, $encoding, $sampleRate)
4141
if (!self::$hasCredentials) {
4242
$this->markTestSkipped('No application credentials were found.');
4343
}
44-
if (!$projectId = getenv('GOOGLE_PROJECT_ID')) {
45-
$this->markTestSkipped('No project ID');
46-
}
4744

4845
$application = new Application();
4946
$application->add(new TranscribeCommand());
@@ -53,7 +50,6 @@ public function testTranscribe($audioFile, $encoding, $sampleRate)
5350
'audio-file' => $audioFile,
5451
'--encoding' => $encoding,
5552
'--sample-rate' => $sampleRate,
56-
'--project' => $projectId
5753
],
5854
['interactive' => false]
5955
);

0 commit comments

Comments
 (0)