在 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 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 应用程序的 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
我希望我提供了完整的信息。
婷婷同学_
函数式编程