googleapis / google-cloud-php

Google Cloud Client Library for PHP
https://cloud.google.com/php/docs/reference
Apache License 2.0
1.09k stars 436 forks source link

class CloudTts not found #4433

Closed BSarmady closed 1 year ago

BSarmady commented 3 years ago

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

Steps to reproduce

  1. Steps in 4432 didn't work, so I created a new auto loader which can find all the existing files and link them
  2. Copied authentication from another sample in googleapis (code below) and it seems to be working, since after a few tries it doesn't show errors and can pass to next line
  3. I'm still required to add environment variable GOOGLE_APPLICATION_CREDENTIALS otherwise TextToSpeechGapicClient throws error cannot authenticate
  4. Added env var
  5. Class CloudTts not found. Searched for it manually using file name and content of file (with file locator and not windows search) and I can't find definition and it is only used in TextToSpeech and no other places

Code example

<?php
namespace Google\Cloud\Samples\Auth;

use Google\Cloud\Storage\StorageClient;

function auth_cloud_explicit($projectId, $serviceAccountPath) {
    $config = [
        'keyFilePath' => $serviceAccountPath,
        'projectId'   => $projectId,
    ];
    $storage = new StorageClient($config);
    foreach ($storage->buckets() as $bucket) {
        printf('Bucket: %s' . PHP_EOL, $bucket->name());
    }
}

auth_cloud_explicit('PROJECT ID FROM CLOUD CONSOLE', 'FULL PHYSICAL PATH TO JSON KEY FILE');
$textToSpeechClient = new \Google\Cloud\TextToSpeech\V1\Gapic\TextToSpeechGapicClient();
try {
    $response = $textToSpeechClient->listVoices();
} finally {
    $textToSpeechClient->close();
}

Screen Output

1 Loaded  Google\Cloud\Storage\StorageClient.php
2 Loaded  Google\Cloud\Core\ArrayTrait.php
3 Loaded  Google\Cloud\Core\ClientTrait.php
4 Loaded  Google\Cloud\Core\JsonTrait.php
5 Loaded  Google\Cloud\Storage\Connection\Rest.php
6 Loaded  Google\Cloud\Storage\Connection\ConnectionInterface.php
7 Loaded  Google\Cloud\Core\RestTrait.php
8 Loaded  Google\Cloud\Core\WhitelistTrait.php
9 Loaded  Google\Cloud\Core\UriTrait.php
10 Loaded  Google\Cloud\Core\RequestWrapper.php
11 Loaded  Google\Cloud\Core\RequestWrapperTrait.php
12 Loaded  Google\Cloud\Core\RetryDeciderTrait.php
13 Loaded  Google\Auth\Cache\MemoryCacheItemPool.php
14 Loaded  Psr\Cache\CacheItemPoolInterface.php
15 Loaded  Google\Auth\HttpHandler\HttpHandlerFactory.php
16 Loaded  GuzzleHttp\Client.php
17 Loaded  GuzzleHttp\ClientInterface.php
18 Loaded  Psr\Http\Client\ClientInterface.php
19 Loaded  GuzzleHttp\ClientTrait.php
20 Loaded  GuzzleHttp\HandlerStack.php
21 Loaded  GuzzleHttp\Utils.php
22 Loaded  GuzzleHttp\Handler\Proxy.php
23 Loaded  GuzzleHttp\Handler\CurlMultiHandler.php
24 Loaded  GuzzleHttp\Handler\CurlFactory.php
25 Loaded  GuzzleHttp\Handler\CurlFactoryInterface.php
26 Loaded  GuzzleHttp\Handler\CurlHandler.php
27 Loaded  GuzzleHttp\Handler\StreamHandler.php
28 Loaded  GuzzleHttp\Middleware.php
29 Loaded  GuzzleHttp\RedirectMiddleware.php
30 Loaded  Google\Auth\HttpHandler\Guzzle7HttpHandler.php
31 Loaded  Google\Auth\HttpHandler\Guzzle6HttpHandler.php
32 Loaded  Google\Cloud\Core\RequestBuilder.php
33 Loaded  GuzzleHttp\Psr7\Uri.php
34 Loaded  Psr\Http\Message\UriInterface.php
35 Loaded  Google\Cloud\Core\Iterator\ItemIterator.php
36 Loaded  Google\Cloud\Core\Iterator\ItemIteratorTrait.php
37 Loaded  Google\Cloud\Core\Iterator\PageIterator.php
38 Loaded  Google\Cloud\Core\Iterator\PageIteratorTrait.php
39 Loaded  Rize\UriTemplate.php
40 Loaded  Rize\UriTemplate\Parser.php
41 Loaded  GuzzleHttp\Psr7\Utils.php
42 Loaded  GuzzleHttp\Psr7\Query.php
43 Loaded  GuzzleHttp\Psr7\Request.php
44 Loaded  Psr\Http\Message\RequestInterface.php
45 Loaded  Psr\Http\Message\MessageInterface.php
46 Loaded  GuzzleHttp\Psr7\MessageTrait.php
47 Loaded  Google\Cloud\Core\ExponentialBackoff.php
48 Loaded  Google\Auth\CredentialsLoader.php
49 Loaded  Google\Auth\FetchAuthTokenInterface.php
50 Loaded  Google\Auth\UpdateMetadataInterface.php
51 Loaded  Google\Auth\Credentials\ServiceAccountCredentials.php
52 Loaded  Google\Auth\GetQuotaProjectInterface.php
53 Loaded  Google\Auth\SignBlobInterface.php
54 Loaded  Google\Auth\ProjectIdProviderInterface.php
55 Loaded  Google\Auth\ServiceAccountSignerTrait.php
56 Loaded  Google\Auth\OAuth2.php
57 Loaded  Google\Auth\FetchAuthTokenCache.php
58 Loaded  Google\Auth\CacheTrait.php
59 Loaded  Google\Auth\Cache\Item.php
60 Loaded  Psr\Cache\CacheItemInterface.php
61 Loaded  Firebase\JWT\JWT.php
62 Loaded  GuzzleHttp\Psr7\Stream.php
63 Loaded  Psr\Http\Message\StreamInterface.php
64 Loaded  GuzzleHttp\RequestOptions.php
65 Loaded  GuzzleHttp\Promise\Create.php
66 Loaded  GuzzleHttp\PrepareBodyMiddleware.php
67 Loaded  GuzzleHttp\Handler\EasyHandle.php
68 Loaded  GuzzleHttp\Handler\HeaderProcessor.php
69 Loaded  GuzzleHttp\Psr7\Response.php
70 Loaded  Psr\Http\Message\ResponseInterface.php
71 Loaded  GuzzleHttp\Promise\FulfilledPromise.php
72 Loaded  GuzzleHttp\Promise\PromiseInterface.php
73 Loaded  GuzzleHttp\Promise\Utils.php
74 Loaded  GuzzleHttp\Promise\TaskQueue.php
75 Loaded  GuzzleHttp\Promise\TaskQueueInterface.php
76 Loaded  GuzzleHttp\Promise\Promise.php
77 Loaded  GuzzleHttp\Promise\Is.php
78 Loaded  Google\Cloud\TextToSpeech\V1\Gapic\TextToSpeechGapicClient.php
79 Loaded  Google\ApiCore\GapicClientTrait.php
80 Loaded  Google\ApiCore\ArrayTrait.php
81 Loaded  Google\ApiCore\ValidationTrait.php
82 Loaded  Google\ApiCore\GrpcSupportTrait.php
83 Loaded  Google\ApiCore\Call.php
84 Loaded  Google\ApiCore\AgentHeader.php
85 Loaded  Google\ApiCore\Version.php
86 Loaded  Google\ApiCore\RetrySettings.php
87 Loaded  Google\ApiCore\ApiStatus.php
88 Loaded  Google\Rpc\Code.php
89 Loaded  Google\ApiCore\CredentialsWrapper.php
90 Loaded  Google\Auth\ApplicationDefaultCredentials.php
91 Loaded  Google\ApiCore\Transport\RestTransport.php
92 Loaded  Google\ApiCore\Transport\TransportInterface.php
93 Loaded  Google\ApiCore\ServiceAddressTrait.php
94 Loaded  Google\ApiCore\Transport\HttpUnaryTransportTrait.php
95 Loaded  Google\ApiCore\RequestBuilder.php
96 Loaded  Google\ApiCore\UriTrait.php
97 Loaded  Google\Cloud\TextToSpeech\V1\ListVoicesRequest.php
98 Loaded  Google\Protobuf\Internal\Message.php
99 Cannot Load GPBMetadata\Google\Cloud\Texttospeech\V1\CloudTts.php

Fatal error:  ....

Error Message

Fatal error:  Uncaught Error: Class 'GPBMetadata\Google\Cloud\Texttospeech\V1\CloudTts' not found in **NGINXROOT**\google-cloud-php\Google\Cloud\TextToSpeech\V1\ListVoicesRequest.php:50
Stack trace:
#0 **NGINXROOT**\google-cloud-php\Google\Cloud\TextToSpeech\V1\Gapic\TextToSpeechGapicClient.php(212): Google\Cloud\TextToSpeech\V1\ListVoicesRequest->__construct()
#1 **NGINXROOT**\google-cloud-php\test.php(39): Google\Cloud\TextToSpeech\V1\Gapic\TextToSpeechGapicClient->listVoices()
#2 {main}
  thrown in **NGINXROOT**\google-cloud-php\Google\Cloud\TextToSpeech\V1\ListVoicesRequest.php on line 50

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

vishwarajanand commented 1 year ago

@BSarmady it may have been a transient issue with TestToSpeech/V1/Gapic/* files. I am able to generate an audio file like this:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;

$text = "Hi there, my name is google cloud php library.";
$client = new TextToSpeechClient();
$input_text = (new SynthesisInput())
    ->setText($text);

// names of voices can be retrieved with $client->listVoices()
$voice = (new VoiceSelectionParams())
    ->setLanguageCode('en-US')
    ->setSsmlGender(SsmlVoiceGender::FEMALE);

$audioConfig = (new AudioConfig())
    ->setAudioEncoding(AudioEncoding::MP3);

$response = $client->synthesizeSpeech($input_text, $voice, $audioConfig);
$audioContent = $response->getAudioContent();

file_put_contents('output.mp3', $audioContent);
print('Audio content written to "output.mp3"' . PHP_EOL);
// exec('/usr/bin/play output.mp3');