|
| 1 | +# Cloud Text-to-Speech: PHP Samples |
| 2 | + |
| 3 | +[![Open in Cloud Shell][shell_img]][shell_link] |
| 4 | + |
| 5 | +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.svg |
| 6 | +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googlecloudplatform/php-docs-samples&page=editor&working_dir=texttospeech |
| 7 | + |
| 8 | +## Description |
| 9 | + |
| 10 | +This command-line application demonstrates how to invoke Cloud Text-to-Speech |
| 11 | +API from PHP. |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +### Authentication |
| 16 | + |
| 17 | +This sample requires you to have authentication setup. Refer to the [Authentication Getting Started Guide](https://cloud.google.com/docs/authentication/getting-started) for instructions on setting up credentials for applications. |
| 18 | + |
| 19 | +## Install Dependencies |
| 20 | + |
| 21 | +1. [Enable the Cloud Text-to-Speech API](https://console.cloud.google.com/flows/enableapi?apiid=texttospeech.googleapis.com). |
| 22 | + |
| 23 | +1. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). |
| 24 | + Run `composer install` (if composer is installed globally). |
| 25 | + |
| 26 | +## Samples |
| 27 | + |
| 28 | +### List voices |
| 29 | +``` |
| 30 | +Usage: |
| 31 | + php texttospeech.php list-voices |
| 32 | +
|
| 33 | +``` |
| 34 | + |
| 35 | +### Synthesize text/ssml |
| 36 | +``` |
| 37 | +Usage: |
| 38 | + php texttospeech.php synthesize-text |
| 39 | + php texttospeech.php synthesize-ssml |
| 40 | +
|
| 41 | +Examples: |
| 42 | + php texttospeech.php synthesize-text -h |
| 43 | + php texttospeech.php synthesize-ssml -h |
| 44 | + php texttospeech.php synthesize-text "Hello there." |
| 45 | + php texttospeech.php synthesize-ssml "Hello there." |
| 46 | +``` |
| 47 | + |
| 48 | +### Synthesize file |
| 49 | +``` |
| 50 | +Usage: |
| 51 | + php texttospeech.php synthesize-text-file |
| 52 | + php texttospeech.php synthesize-ssml-file |
| 53 | +
|
| 54 | +Examples: |
| 55 | + php texttospeech.php synthesize-text-file -h |
| 56 | + php texttospeech.php synthesize-ssml-file -h |
| 57 | + php texttospeech.php synthesize-text-file resources/hello.txt |
| 58 | + php texttospeech.php synthesize-ssml-file resources/hello.ssml |
| 59 | +``` |
| 60 | + |
| 61 | +## The client library |
| 62 | + |
| 63 | +This sample uses the [Google Cloud Client Library for PHP][google-cloud-php]. |
| 64 | +You can read the documentation for more details on API usage and use GitHub |
| 65 | +to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues]. |
| 66 | + |
| 67 | +## Troubleshooting |
| 68 | + |
| 69 | +If you get the following error, set the environment variable `GCLOUD_PROJECT` to your project ID: |
| 70 | + |
| 71 | +``` |
| 72 | +[Google\Cloud\Core\Exception\GoogleException] |
| 73 | +No project ID was provided, and we were unable to detect a default project ID. |
| 74 | +``` |
| 75 | + |
| 76 | +If you have not set a timezone you may get an error from php. This can be resolved by: |
| 77 | + |
| 78 | + 1. Finding where the php.ini is stored by running `php -i | grep 'Configuration File'` |
| 79 | + 1. Finding out your timezone from the list on this page: http://php.net/manual/en/timezones.php |
| 80 | + 1. Editing the php.ini file (or creating one if it doesn't exist) |
| 81 | + 1. Adding the timezone to the php.ini file e.g., adding the following line: `date.timezone = "America/Los_Angeles"` |
| 82 | + |
| 83 | +[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php |
| 84 | +[google-cloud-php-source]: https://github.com/GoogleCloudPlatform/google-cloud-php |
| 85 | +[google-cloud-php-issues]: https://github.com/GoogleCloudPlatform/google-cloud-php/issues |
0 commit comments