我希望有人可以帮助我弄清楚如何将Google的语音传达给文本API运行。
https://github.com/googlecloodplatform/php-docs-samples/tree/master/master/speech/api
我要运行的特定代码是:src/functions/transcribe_sync.php
在末尾添加了一条线以调用函数:
transcribe_sync("mono.flac", 'en-US');
无法找到依赖关系。我一直在和作曲家一起玩,但无法弄清楚。
引起错误:
php transcribe_sync.php
PHP Fatal error: Uncaught Error: Class 'GoogleCloudSpeechSpeechClient' 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): GoogleCloudSamplesSpeechtranscribe_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文件:
{
"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(似乎真的很神秘。
我是错误的方式吗?感谢您的帮助!
样品的构造方式是通过根中的speech.php
文件运行。要直接运行transcribe_sync.php
,您需要包括作曲家自动加载器:
require_once "/path/to/vendor/autoload.php";
用安装作曲家依赖的路径替换/path/to
。
另外(我建议此选项(,要运行,而无需对示例代码进行任何更改,请在命令行中运行:
php speech.php transcribe mono.flac