【发布时间】:2020-05-12 17:51:23
【问题描述】:
在 App Engine flex 环境中部署 PHP 应用程序时尝试创建 Google 的 TextToSpeechClient 类的实例时遇到了致命的服务器错误。在本地主机上它可以正常工作。以下是错误信息:
"注意:PHP 消息: PHP致命错误:未捕获的错误:类 'Google\Cloud\TextToSpeech\V1\TextToSpeechClient' 未在 /app/web/get_voices2.php:46"
我的 get_voices2.php
<?php
// includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
require_once('includes/dbPDO.php');
// Imports the Cloud Client Library
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;
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 app's web directory structure
我的 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
我希望我提供了完整的信息。
【问题讨论】:
-
这与 Composer 本身或“app.yaml”有什么关系?您尝试过什么调试问题?
标签: php google-app-engine composer-php google-text-to-speech app.yaml