在 App Engine flex 環境中部署 PHP 應用程序時,嘗試創建 Googles 的 TextToSpeechClient 類實例時出現致命服務器錯誤。在本地主機上,它可以正常工作。以下是錯誤信息:“注意:PHP 消息:PHP 致命錯誤:未捕獲錯誤:在 /app/web/get_voices2.php:46 中找不到類 'Google\Cloud\TextToSpeech\V1\TextToSpeechClient'”我的 get_voices2.php<?php// includes the autoloader for libraries installed with composerrequire __DIR__ . '/vendor/autoload.php';require_once('includes/dbPDO.php');// Imports the Cloud Client Libraryuse 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;use Google\Cloud\Storage\StorageClient;if (isset($_POST['language']) && isset($_POST['quality'])) { $storage = new StorageClient(); $language = $_POST['language']; $quality = $_POST['quality']; $dsn = getenv('MYSQL_DSN'); $user = getenv('MYSQL_USER'); $password = getenv('MYSQL_PASSWORD'); $dbh = OpenCon($dsn,$user,$password); echo getListVoices($language, $quality, $dbh);}function getListVoices($lan, $quality,$conn) { $optionData = '<option id = "0" disabled>Select voice</option>'; // instantiates a client on line 46 $client = new TextToSpeechClient(['credentials' => json_decode(file_get_contents('cred.json'), true)]); $response = $client->listVoices(); $voices = $response->getVoices(); } 這是我的 App Engine 文件夾結構。請注意 app.yaml 文件不在 web 目錄中。它與 /various 和 /php-docs-sample PHP 應用程序的 Web 目錄結構位于同一目錄中我的 composer.json 文件:{ "require": { "google/cloud-speech": "^1.0.1", "google/gax": "^1.1", "grpc/grpc": "^1.4", "google/protobuf": "^v3.3.0", "google/auth": "^1.8", "phpseclib/phpseclib": "^2.0" }}我通過運行以下命令在 App Engine 上部署我的項目:gcloud app deploy -version dev我希望我提供了完整的信息。
2 回答

婷婷同學_
TA貢獻1844條經驗 獲得超8個贊
根據它的存儲庫,該類在包中給出google/cloud-text-to-speech
- 但根據您的composer.json
,您不需要該包。
你到底為什么要google/cloud-core
在這個部分要求?require-dev
這是一個好兆頭,表明您為開發系統使用了一組不同于生產系統的特定于應用程序的類。通常,這應該只包括屬于您開發的一部分的東西(例如:調試工具、測試工具),而不是那些提供應用程序基礎的東西

函數式編程
TA貢獻1807條經驗 獲得超9個贊
我只是用一個有效的解決方案來跟進我的問題。
$?composer?require?google/cloud-text-to-speech
代替:
$?composer?require?google/cloud-speech
Composer 自動將以下行添加到 composer.json
{?? ??"require":?{?? ??????"google/cloud-text-to-speech":?"^1.0"????? ????} }
然后客戶端被實例化沒有任何問題
$client?=?new?TextToSpeechClient();
- 2 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消