Reputation: 27
I was hoping someone could help me figure out how to get google's speech to text api running.
https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/speech/api
The specific code I'm trying to run is: src/functions/transcribe_sync.php
with a line added at the end to call the function:
transcribe_sync("mono.flac", 'en-US');
It can't locate a dependency. I've been playing around with composer but haven't been able to figure it out.
Heres the error:
php transcribe_sync.php
PHP Fatal error: Uncaught Error: Class 'Google\Cloud\Speech\SpeechClient' not found in /home/bhaag/Documents/php-docs-samples-master/speech/api/src/functions/transcribe_sync.php:45
Stack trace:
#0 /home/bhaag/Documents/php-docs-samples-master/speech/api/src/functions/transcribe_sync.php(55): Google\Cloud\Samples\Speech\transcribe_sync('mono.flac', 'en-US')
#1 {main}
thrown in /home/bhaag/Documents/php-docs-samples-master/speech/api/src/functions/transcribe_sync.php on line 45
Heres my composer.json file:
{
"require": {
"google/cloud-speech": "^0.2",
"google/cloud-storage": "^1.0",
"google/gax": "^0.8.1",
"google/proto-client-php": "^0.10.0",
"symfony/console": "^3.0",
"php-ffmpeg/php-ffmpeg": "^0.9.3"
},
"autoload": {
"psr-4": {
"Google\\Cloud\\Samples\\Speech\\": "src/"
},
"files": [
"src/functions/streaming_recognize.php",
"src/functions/transcribe_async.php",
"src/functions/transcribe_async_gcs.php",
"src/functions/transcribe_sync.php",
"src/functions/transcribe_sync_gcs.php"
]
},
"require-dev": {
"phpunit/phpunit": "~4"
}
}
I've been able to get the full speech sample running so I know I have all the credentials set up correctly but it seemed really cryptic to work with the full sample (speech.php in the main directory).
Am I going about this the wrong way? Thanks for any help!
Upvotes: 1
Views: 1631
Reputation: 3516
The samples are constructed in such a way as to be run via the speech.php
file in the root. To run transcribe_sync.php
directly, you'll need to include the composer autoloader:
require_once "/path/to/vendor/autoload.php";
Replace the /path/to
with the path to where your composer dependencies are installed.
Alternatively, (I recommend this option), to run without any changes to the sample code, run this at the command line:
php speech.php transcribe mono.flac
Upvotes: 1