Download Google Cloud TTS as MP3 with PHP
composer require google/cloud-text-to-speech
Since this also includes a Cloudflare Turnstile implementation for bot protection, get your Turnstile keys here: https://dash.cloudflare.com/ Update config.php and index.html files accordingly.
And then setup your Google Cloud TTS: Set up a Google Cloud project:
- Go to the Google Cloud Console (https://console.cloud.google.com/).
- Click on the project dropdown and select "New Project".
- Give your project a name and click "Create". Enable the Text-to-Speech API:
- In the Google Cloud Console, go to the Navigation menu (hamburger icon) and select "APIs & Services" > "Library".
- Search for "Cloud Text-to-Speech API" and click on it.
- Click "Enable" to activate the API for your project. Create credentials:
- In the Google Cloud Console, go to "APIs & Services" > "Credentials".
- Click "Create Credentials" and select "Service Account".
- Fill in the service account details and click "Create".
- Grant this service account the "Cloud Text-to-Speech API User" role.
- Click "Continue" and then "Done".
- In the Credentials page, find your new service account and click on it.
- Go to the "Keys" tab and click "Add Key" > "Create new key".
- Choose JSON as the key type and click "Create". This will download a JSON file.
- Place the json file in the creds folder and update the config.php file accordingly.