NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ 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.
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [2.2.2 (latest)](/php/docs/reference/cloud-text-to-speech/latest)\n- [2.2.1](/php/docs/reference/cloud-text-to-speech/2.2.1)\n- [2.0.1](/php/docs/reference/cloud-text-to-speech/2.0.1)\n- [1.12.2](/php/docs/reference/cloud-text-to-speech/1.12.2)\n- [1.11.0](/php/docs/reference/cloud-text-to-speech/1.11.0)\n- [1.10.0](/php/docs/reference/cloud-text-to-speech/1.10.0)\n- [1.9.1](/php/docs/reference/cloud-text-to-speech/1.9.1)\n- [1.8.5](/php/docs/reference/cloud-text-to-speech/1.8.5)\n- [1.7.2](/php/docs/reference/cloud-text-to-speech/1.7.2)\n- [1.6.1](/php/docs/reference/cloud-text-to-speech/1.6.1)\n- [1.5.6](/php/docs/reference/cloud-text-to-speech/1.5.6)\n- [1.4.5](/php/docs/reference/cloud-text-to-speech/1.4.5) \n\nCloud Text-to-Speech for PHP\n============================\n\n\u003e Idiomatic PHP client for [Cloud Text-to-Speech](https://cloud.google.com/text-to-speech/).\n\n[](https://packagist.org/packages/google/cloud-text-to-speech) [](https://packagist.org/packages/google/cloud-text-to-speech)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-text-to-speech\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n require __DIR__ . '/vendor/autoload.php';\n\n use Google\\Cloud\\TextToSpeech\\V1\\AudioConfig;\n use Google\\Cloud\\TextToSpeech\\V1\\AudioEncoding;\n use Google\\Cloud\\TextToSpeech\\V1\\SynthesisInput;\n use Google\\Cloud\\TextToSpeech\\V1\\Client\\TextToSpeechClient;\n use Google\\Cloud\\TextToSpeech\\V1\\VoiceSelectionParams;\n use Google\\Cloud\\TextToSpeech\\V1\\SynthesizeSpeechRequest;\n\n $textToSpeechClient = new TextToSpeechClient();\n\n $input = new SynthesisInput();\n $input-\u003esetText('Japan\\'s national soccer team won against Colombia!');\n $voice = new VoiceSelectionParams();\n $voice-\u003esetLanguageCode('en-US');\n $audioConfig = new AudioConfig();\n $audioConfig-\u003esetAudioEncoding(AudioEncoding::MP3);\n $request = (new SynthesizeSpeechRequest())\n -\u003esetInput($input)\n -\u003esetVoice($voice)\n -\u003esetAudioConfig($audioConfig);\n\n $resp = $textToSpeechClient-\u003esynthesizeSpeech($request);\n file_put_contents('test.mp3', $resp-\u003egetAudioContent());\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in\nany minor or patch releases. We will address issues and requests with the highest priority.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/text-to-speech/docs)."]]