PHP-Google Speech API:找不到类“ Google\Cloud\Speech\SpeechClient” [英] PHP - Google Speech API: Class 'Google\Cloud\Speech\SpeechClient' not found
问题描述
我希望有人能帮助我弄清楚如何使Google语音运行到text api上。
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
我正在尝试的特定代码要运行的是:src / functions / transcribe_sync.php
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.
此处出现错误:
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
在这里放置我的composer.json文件:
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"
}
}
我已经能够运行完整的语音示例,所以我知道我已经正确设置了所有凭据,但是使用完整示例(主目录中的speech.php)似乎真的很神秘。
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!
推荐答案
示例的构建方式可以通过运行根目录中的speech.php
文件。要直接运行 transcribe_sync.php
,您需要包括composer自动加载器:
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";
将 / path / to
替换为
或者,(建议使用此选项)要在不对示例代码进行任何更改的情况下运行,请在命令行上运行:
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
这篇关于PHP-Google Speech API:找不到类“ Google\Cloud\Speech\SpeechClient”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!