google/cloud-text-to-speech

PHP的云文本转语音客户端

v1.9.1 2024-08-26 22:48 UTC

README

用于云文本转语音的PHP惯用客户端。

Latest Stable Version Packagist

注意: 此仓库是Google Cloud PHP项目的一部分。任何支持请求、错误报告或开发贡献应指向该项目。

安装

首先,安装PHP的首选依赖关系管理器 Composer

现在安装此组件

$ composer require google/cloud-text-to-speech

身份验证

请参阅我们的身份验证指南以获取有关客户端身份验证的更多信息。身份验证后,您即可开始进行请求。

示例

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

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

$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());

版本

此组件被认为是GA(一般可用)。因此,它不会在任何次要或补丁版本中引入向后不兼容的更改。我们将优先解决问题和请求。

下一步

  1. 了解官方文档