@jackdbd/eleventy-plugin-text-to-speech
Eleventy plugin that send messages to a Telegram chat of your choice.
Installation
npm install --save-dev @jackdbd/eleventy-plugin-text-to-speech
Before you can begin using the Text-to-Speech API, you must enable it. Using Cloud Shell, you can enable the API with the following command:
gcloud services enable texttospeech.googleapis.com
Create a service account that can use the Text-to-Speech API.
gcloud iam service-accounts create sa-text-to-speech-user \
--display-name "Text-to-Speech user SA"
Usage
const { textToSpeechPlugin } = require('@jackdbd/eleventy-plugin-text-to-speech')
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(textToSpeechPlugin, {
audioEncoding: 'OGG_OPUS',
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
regexPattern: '.*/posts/.*.html$',
voice: { languageCode: 'en-GB', name: 'en-GB-Wavenet-C' }
})
}
:warning: The Cloud Text-to-Speech API has a limit of 5000 characters.
See also:
Configuration
Options
Option | Default | Explanation |
---|
audioEncoding | OGG_OPUS | Encoding for the audio file. It must be one of supported audio encodings of the Cloud Text-to-Speech API. |
regexPattern | .*.html$ | regex pattern to find text files to convert into speech. |
keyFilename | process.env.GOOGLE_APPLICATION_CREDENTIALS | credentials for the Cloud Text-to-Speech API. |
voiceLanguageCode | en-US | Name of the Text-to-Speech languageCode to use. See list here. |
voiceName | en-US-Standard-J | Name of the Text-to-Speech voice to use. See list here. |
:warning: Don't forget to set either keyFilename
or the GOOGLE_APPLICATION_CREDENTIALS
environment variable on your build server. For example, if your build runs on the Github CI, use GitHub secrets; if the build runs on Netlify, use Build environment variables.
GCP Cloud Storage
gsutil ls -p $GCP_PROJECT_ID
https://cloud.google.com/storage/docs/using-uniform-bucket-level-access#gsutil
https://cloud.google.com/storage/docs/access-control
Create a Cloud Storage bucket with uniform bucket-level access.
gsutil mb \
-p $GCP_PROJECT_ID \
-l $CLOUD_STORAGE_LOCATION \
-c nearline \
-b on \
gs://bkt-eleventy-plugin-text-to-speech-audio-files
Check that uniform bucket-level access is enabled:
gsutil uniformbucketlevelaccess get \
gs://bkt-eleventy-plugin-text-to-speech-audio-files
Add a couple of labels to the bucket:
gsutil label ch \
-l CUSTOMER:$CUSTOMER \
gs://bkt-eleventy-plugin-text-to-speech-audio-files
Check that the bucket has the expected labels:
gsutil label get gs://bkt-eleventy-plugin-text-to-speech-audio-files
``sh
gsutil cp
./packages/demo-site/_site/posts/capybaras-are-cool.mp3
gs://bkt-eleventy-plugin-text-to-speech-audio-files
Make the bucket's objects publicly readable:
```sh
gsutil iam ch allUsers:objectViewer \
gs://bkt-eleventy-plugin-text-to-speech-audio-files
List all files in the bucket:
gsutil ls gs://bkt-eleventy-plugin-text-to-speech-audio-files