为什么软件包缺少"音频编码"?



我正在尝试创建一个使用Google API Text-to-Speech的文本到语音服务。Hee是我的代码:

// Setup Google Client
require_once '../../plugins/php/google-api-php-client-2.4.1/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('../../plugins/php/google-api-php-client-2.4.1/credentials.json');
$client->addScope(Google_Service_Texttospeech::CLOUD_PLATFORM);
$service = new Google_Service_Texttospeech($client);
// Setup Request
$input = new Google_Service_Texttospeech_SynthesisInput();
$input->setText('Japan's national soccer team won against Colombia!');
$voice = new Google_Service_Texttospeech_VoiceSelectionParams();
$voice->setLanguageCode('en-US');
$audioConfig = new Google_Service_Texttospeech_AudioConfig();
$audioConfig->setAudioEncoding(Google_Service_Texttospeech_AudioEncoding::MP3);

除了给出错误的最后一行:之外,一切都正常

致命错误:未捕获错误:在/home/******/public_html/services/remotes/post/convert-text-to-speech.php中找不到类"AudioEncoding"。php:28堆栈跟踪:在第28行的/home/****/public_html/services/remotes/post/conconvert-text-to-speech.php中抛出#0{main}

有什么帮助吗?

您似乎正在使用Google Apis PHP客户端库,该库使您能够在服务器上使用Gmail、Drive或YouTube等Google API。

你应该使用谷歌云PHP客户端库这个客户端支持访问谷歌云平台服务。

require __DIR__ . '/vendor/autoload.php';
use GoogleCloudTextToSpeechV1AudioConfig;
use GoogleCloudTextToSpeechV1AudioEncoding;
use GoogleCloudTextToSpeechV1SynthesisInput;
use GoogleCloudTextToSpeechV1TextToSpeechClient;
use GoogleCloudTextToSpeechV1VoiceSelectionParams;
$textToSpeechClient = new TextToSpeechClient();
$input = new SynthesisInput();
$input->setText('Japan's national soccer team won against Colombia!');
$voice = new VoiceSelectionParams();
$voice->setLanguageCode('en-US');
$audioConfig = new AudioConfig();
$audioConfig->setAudioEncoding(AudioEncoding::MP3);
$resp = $textToSpeechClient->synthesizeSpeech($input, $voice, $audioConfig);
file_put_contents('test.mp3', $resp->getAudioContent());

最新更新