01.
require
__DIR__ .
'/vendor/autoload.php'
;
02.
03.
use
Google\Cloud\TextToSpeech\V1\AudioConfig;
04.
use
Google\Cloud\TextToSpeech\V1\AudioEncoding;
05.
use
Google\Cloud\TextToSpeech\V1\SynthesisInput;
06.
use
Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
07.
use
Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
08.
09.
$textToSpeechClient
=
new
TextToSpeechClient();
10.
11.
$input
=
new
SynthesisInput();
12.
$input
->setText(
'Japan\'s national soccer team won against Colombia!'
);
13.
$voice
=
new
VoiceSelectionParams();
14.
$voice
->setLanguageCode(
'en-US'
);
15.
$audioConfig
=
new
AudioConfig();
16.
$audioConfig
->setAudioEncoding(AudioEncoding::MP3);
17.
18.
$resp
=
$textToSpeechClient
->synthesizeSpeech(
$input
,
$voice
,
$audioConfig
);
19.
file_put_contents
(
'test.mp3'
,
$resp
->getAudioContent());