These command-line samples demonstrates how to invoke Cloud Text-to-Speech API from PHP.
This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.
-
Install dependencies via Composer. Run
composer install(if composer is installed globally).
Run php src/SNIPPET_NAME.php. The usage will print for each if arguments are required:
$ php src/synthesize_text.php
Usage: php src/synthesize_text.php TEXT
$ php src/list_voices.php
Name: ar-XA-Wavenet-A
Supported language: ar-XA
SSML voice gender: FEMALE
Natural Sample Rate Hertz: 24000
...Usage:
php src/synthesize_text.php <TEXT>
php src/synthesize_ssml.php <SSML>
Examples:
php src/synthesize_text_audio_profile.php
php src/synthesize_text.php "Hello there."
php src/synthesize_ssml.php "<speak>Hello there.</speak>"
php src/synthesize_text_effects_profile.php "Hello there." "handset-class-device"
Usage:
php src/synthesize_text_file.php <FILE_PATH>
php src/synthesize_ssml_file.php <FILE_PATH>
php src/synthesize_text_effects_profile_file.php <FILE_PATH> <AUDIO_PROFILE>
Examples:
php src/synthesize_text_file.php
php texttospeech.php synthesize_ssml_file.php
php src/synthesize_text_audio_profile_file.php
php src/synthesize_text_file.php resources/hello.txt
php src/synthesize_ssml_file.php resources/hello.ssml
php src/synthesize_text_effects_profile_file.php resources/hello.txt "handset-class-device"
This sample uses the Google Cloud Client Library for PHP. You can read the documentation for more details on API usage and use GitHub to browse the source and report issues.
If you get the following error, set the environment variable GCLOUD_PROJECT to your project ID:
[Google\Cloud\Core\Exception\GoogleException]
No project ID was provided, and we were unable to detect a default project ID.
If you have not set a timezone you may get an error from php. This can be resolved by:
- Finding where the php.ini is stored by running
php -i | grep 'Configuration File' - Finding out your timezone from the list on this page: http://php.net/manual/en/timezones.php
- Editing the php.ini file (or creating one if it doesn't exist)
- Adding the timezone to the php.ini file e.g., adding the following line:
date.timezone = "America/Los_Angeles"