Cloud Text-to-Speech for PHP
Idiomatic PHP client for Cloud Text-to-Speech., (*1)
, (*2)
NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project., (*3)
Installation
To begin, install the preferred dependency manager for PHP, Composer., (*4)
Now install this component:, (*5)
$ composer require google/cloud-text-to-speech
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests., (*6)
Sample
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\Client\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
use Google\Cloud\TextToSpeech\V1\SynthesizeSpeechRequest;
$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);
$request = (new SynthesizeSpeechRequest())
->setInput($input)
->setVoice($voice)
->setAudioConfig($audioConfig);
$resp = $textToSpeechClient->synthesizeSpeech($request);
file_put_contents('test.mp3', $resp->getAudioContent());
Debugging
Please see our Debugging guide
for more information about the debugging tools., (*7)
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in
any minor or patch releases. We will address issues and requests with the highest priority., (*8)
Next Steps
- Understand the official documentation.