【问题标题】:how to use google cloud speech API如何使用谷歌云语音 API
【发布时间】:2017-05-01 09:24:44
【问题描述】:

我是使用 google API 的新手。我正在尝试使用谷歌语音识别,将我的语音转换为文本,反之亦然。但不知道如何使用谷歌语音API。我使用这个命令下载了谷歌云包

composer require google/cloud

但我不知道如何使用它。我正在从此链接关注教程https://github.com/GoogleCloudPlatform/google-cloud-php。 但它向我显示错误。

Fatal error:  Uncaught Google\Cloud\Exception\ServiceException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php:221
Stack trace:

#0 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(185): Google\Cloud\RequestWrapper->convertToGoogleException(Object(DomainException))
#1 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(167): Google\Cloud\RequestWrapper->fetchCredentials()
#2 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(150): Google\Cloud\RequestWrapper->getToken()
#3 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(131): Google\Cloud\RequestWrapper->signRequest(Object(GuzzleHttp\Psr7\Request))
#4 /var/www/html/googlevoice/vendor/google/cloud/src/RestTrait.php(78): Google\Cloud\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#5 /var/www/html/googlevoice/vendor/goo in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php on line 221

【问题讨论】:

  • 当您点击消息中提供给您的链接时会发生什么? ---> developers.google.com/accounts/docs/…
  • 我没有得到任何东西。我刚刚收到上述错误。
  • 再次创建凭证教程。你的代码看不懂。

标签: google-api-php-client google-speech-api


【解决方案1】:

首先看起来您需要生成服务帐户凭据:)。

请查看本指南以进行设置:https://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/guides/authentication

从那里您将要执行以下操作:

require 'vendor/autoload.php';

use Google\Cloud\Storage\StorageClient;

// Pass the key file directly into your client.
$storage = new StorageClient([
    'keyFilePath' => '/path/to/service/credentials.json'
]);

// OR

// Store the key file as an environment variable
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/credentials.json');

$storage = new StorageClient();

【讨论】:

  • 感谢 David S 的回复
  • 我启用了您提供的链接上提供的所有 api。但在那之后我收到错误致命错误:未捕获的 Google\Cloud\Exception\ServiceException: { "error": "deleted_client", "error_description": "The OAuth client was deleted." } 在 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php:219
  • 有趣!如果您还没有尝试过,我建议您重新生成您的服务帐户凭据。如果这不起作用,我会直接联系支持团队 - cloud.google.com/support
猜你喜欢
  • 2023-04-09
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多