From 0f5564d614321dd74d8fa502ce464af915fc9238 Mon Sep 17 00:00:00 2001 From: Jacob Cable Date: Mon, 8 May 2023 22:59:56 +0100 Subject: [PATCH] refactor(text-to-speech): update extension details for publishing --- firestore-text-to-speech/PREINSTALL.md | 18 ----------- .../functions/src/types.ts | 16 ---------- text-to-speech/CHANGELOG.md | 3 ++ .../POSTINSTALL.md | 22 +++++++------ text-to-speech/PREINSTALL.md | 30 +++++++++++++++++ .../README.md | 6 ++-- .../extension.yaml | 18 +++++------ .../functions/.gitignore | 0 .../functions/__tests__/__mocks__/index.ts | 0 .../functions/__tests__/functions.test.ts | 0 .../functions/__tests__/helpers.ts | 0 .../__tests__/helpers/setupEnvironment.ts | 0 .../functions/__tests__/jest.setup.ts | 0 .../functions/__tests__/tsconfig.json | 0 .../functions/jest.config.js | 0 .../functions/package.json | 0 .../functions/src/config.ts | 2 +- .../functions/src/index.ts | 16 ++++++++++ .../functions/src/logs.ts | 0 text-to-speech/functions/src/types.ts | 32 +++++++++++++++++++ .../functions/src/util.ts | 15 +++++++++ .../functions/tsconfig.json | 0 22 files changed, 121 insertions(+), 57 deletions(-) delete mode 100644 firestore-text-to-speech/PREINSTALL.md delete mode 100644 firestore-text-to-speech/functions/src/types.ts create mode 100644 text-to-speech/CHANGELOG.md rename {firestore-text-to-speech => text-to-speech}/POSTINSTALL.md (74%) create mode 100644 text-to-speech/PREINSTALL.md rename {firestore-text-to-speech => text-to-speech}/README.md (92%) rename {firestore-text-to-speech => text-to-speech}/extension.yaml (95%) rename {firestore-text-to-speech => text-to-speech}/functions/.gitignore (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/__mocks__/index.ts (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/functions.test.ts (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/helpers.ts (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/helpers/setupEnvironment.ts (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/jest.setup.ts (100%) rename {firestore-text-to-speech => text-to-speech}/functions/__tests__/tsconfig.json (100%) rename {firestore-text-to-speech => text-to-speech}/functions/jest.config.js (100%) rename {firestore-text-to-speech => text-to-speech}/functions/package.json (100%) rename {firestore-text-to-speech => text-to-speech}/functions/src/config.ts (98%) rename {firestore-text-to-speech => text-to-speech}/functions/src/index.ts (76%) rename {firestore-text-to-speech => text-to-speech}/functions/src/logs.ts (100%) create mode 100644 text-to-speech/functions/src/types.ts rename {firestore-text-to-speech => text-to-speech}/functions/src/util.ts (64%) rename {firestore-text-to-speech => text-to-speech}/functions/tsconfig.json (100%) diff --git a/firestore-text-to-speech/PREINSTALL.md b/firestore-text-to-speech/PREINSTALL.md deleted file mode 100644 index 88628a3a..00000000 --- a/firestore-text-to-speech/PREINSTALL.md +++ /dev/null @@ -1,18 +0,0 @@ -This extension converts text from Firestore documents into speech using the Google Cloud Text-to-Speech API and saves the generated audio files in Cloud Storage for Firebase. - - -### Monitor the specified Firestore collection for new documents -This extension reads the text field from newly created documents and converts the text into speech using the Google Cloud Text-to-Speech API. - -### Saving audio to the defined storage bucket -The the resulting audio files are then saved in the specified Cloud Storage bucket. - -### Billing -To install an extension, your project must be on the Blaze (pay as you go) plan. - -- You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used). -- This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service's no-cost tier: - - Google Cloud Text-to-Speech API - - Cloud Firestore - - Cloud Storage for Firebase - - Cloud Functions (Node.js 10+ runtime. See [FAQs](https://firebase.google.com/support/faq#extensions-pricing)) diff --git a/firestore-text-to-speech/functions/src/types.ts b/firestore-text-to-speech/functions/src/types.ts deleted file mode 100644 index 2f3e388e..00000000 --- a/firestore-text-to-speech/functions/src/types.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as tts from '@google-cloud/text-to-speech'; - -export type ISynthesizeSpeechRequest = - tts.protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest; -export type ISynthesizeSpeechResponse = - tts.protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse; -export type AudioEncoding = - | tts.protos.google.cloud.texttospeech.v1.AudioEncoding - | 'AUDIO_ENCODING_UNSPECIFIED' - | 'LINEAR16' - | 'MP3' - | 'OGG_OPUS' - | 'MULAW' - | 'ALAW'; -export type SsmlVoiceGender = - tts.protos.google.cloud.texttospeech.v1.SsmlVoiceGender; diff --git a/text-to-speech/CHANGELOG.md b/text-to-speech/CHANGELOG.md new file mode 100644 index 00000000..be28b3d3 --- /dev/null +++ b/text-to-speech/CHANGELOG.md @@ -0,0 +1,3 @@ +## Version 0.1.0 + +Initial release of the _Convert Text to Speech_ extension. \ No newline at end of file diff --git a/firestore-text-to-speech/POSTINSTALL.md b/text-to-speech/POSTINSTALL.md similarity index 74% rename from firestore-text-to-speech/POSTINSTALL.md rename to text-to-speech/POSTINSTALL.md index eec57bba..06149098 100644 --- a/firestore-text-to-speech/POSTINSTALL.md +++ b/text-to-speech/POSTINSTALL.md @@ -1,13 +1,14 @@ +## See it in action + This extension will automatically convert text from Firestore documents into speech and save the generated audio files in Cloud Storage for Firebase. -### See it in action -To use this extension, ensure that each document in the specified Firestore collection contains a text field with the content you want to convert to speech. +To use this extension, ensure that each document in the specified Firestore collection contains a text field with the content you want to convert to speech. If you enabled per-document overrides during installation, you can also include fields such as languageCode, ssmlGender, audioEncoding, and voiceName in the document for customization. -### Example Usage +## Example Usage -```js +```javascript admin .firestore() .collection("${param:COLLECTION_PATH}") @@ -20,15 +21,16 @@ admin }); ``` -### Access generated audio files -Once the extension is installed, it will automatically process new documents in the ${param:COLLECTION_PATH} collection and store the resulting audio files in your ${param:BUCKET} Cloud Storage bucket. +## Access generated audio files + +Once the extension is installed, it will automatically process new documents in the ${param:COLLECTION_PATH} collection and store the resulting audio files in your ${param:BUCKET} Cloud Storage bucket. The files will be named using the document ID with an appropriate file extension (e.g., .mp3 for MP3 files). -### Error handling: +## Error handling + If there are any errors during the text-to-speech conversion process, the extension will log the error message in the Cloud Functions logs. Make sure to monitor these logs and handle any errors appropriately in your application. -### Monitoring: -As a best practice, you can monitor the activity of your installed extension, including its health, usage, and logs, by visiting the Firebase Extensions dashboard in the Firebase Console. +## Monitoring -The Text-to-Speech Extension is now installed and ready to enhance your application by converting text in Firestore documents into speech. \ No newline at end of file +As a best practice, you can [monitor the activity](https://firebase.google.com/docs/extensions/manage-installed-extensions#monitor) of your installed extension, including checks on its health, usage, and logs. diff --git a/text-to-speech/PREINSTALL.md b/text-to-speech/PREINSTALL.md new file mode 100644 index 00000000..14666e6e --- /dev/null +++ b/text-to-speech/PREINSTALL.md @@ -0,0 +1,30 @@ +This extension converts text from Firestore documents into speech using the Google Cloud Text-to-Speech API. + +Upon install you will be asked to provide a Firestore collection path and a Storage path. Any document writes to this collection will trigger a Cloud Function that does the following: + +* Generates an audio version of the same text +* Stores it in Cloud Storage in the specified path +* Writes the path to the Storage object back in the same document. + +## Use Cases +* Accessibility: A key strength of TTS lies in fostering inclusive access to digital content for people with visual impairments or who face reading challenges. By utilizing TTS, we can work towards providing equal opportunities for everyone to obtain information, acknowledging and embracing the diverse abilities and requirements of all users. +* Language learning: TTS can be a handy tool for language learners, as it can help users to practice their pronunciation and improve their listening comprehension. By providing accurate and natural-sounding speech, TTS can help language learners to develop their language skills in a more immersive and interactive way. +* Navigation: In-car navigation systems often use TTS to give drivers turn-by-turn directions. TTS can help drivers keep their eyes on the road and avoid distractions by providing spoken instructions, improving safety. +* Virtual assistants: Virtual assistants like Siri, Alexa, and Google Assistant rely heavily on TTS to provide users with helpful information and complete tasks. Using TTS, virtual assistants can create a more natural and conversational experience for users, enhancing their overall usability. + +## Additional Setup + +Before installing this extension, make sure that you've set up a [Cloud Firestore database](https://firebase.google.com/docs/firestore/quickstart) and [Cloud Storage bucket](https://firebase.google.com/docs/storage) in your Firebase project. + +## Billing + +To install an extension, your project must be on the Blaze (pay as you go) plan. + +You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used). + +This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service's no-cost tier: + +* [Google Cloud Text-to-Speech API](https://cloud.google.com/text-to-speech#section-11) +* Cloud Firestore +* Cloud Storage +* Cloud Functions (Node.js 14+ runtime. See [FAQs](https://firebase.google.com/support/faq#extensions-pricing)) diff --git a/firestore-text-to-speech/README.md b/text-to-speech/README.md similarity index 92% rename from firestore-text-to-speech/README.md rename to text-to-speech/README.md index 3c1f7ea2..46559694 100644 --- a/firestore-text-to-speech/README.md +++ b/text-to-speech/README.md @@ -1,8 +1,8 @@ -# Text to Speech with Firestore and Storage +# Convert Text to Speech -**Author**: Firebase (**[https://firebase.google.com](https://firebase.google.com)**) +**Author**: Google Cloud (**[https://cloud.google.com/](https://cloud.google.com/)**) -**Description**: Converts text from Firestore documents into spoken audio files using Google Cloud Text-to-Speech API. +**Description**: Converts Firestore documents to audio files stored in Cloud Storage using Cloud Text to Speech. diff --git a/firestore-text-to-speech/extension.yaml b/text-to-speech/extension.yaml similarity index 95% rename from firestore-text-to-speech/extension.yaml rename to text-to-speech/extension.yaml index a0f4f88c..2911821b 100644 --- a/firestore-text-to-speech/extension.yaml +++ b/text-to-speech/extension.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,22 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: firestore-text-to-speech -version: 0.1.11 +name: text-to-speech +version: 0.1.0 specVersion: v1beta -displayName: Text to Speech with Firestore and Storage +displayName: Convert Text to Speech description: - Converts text from Firestore documents into spoken audio files using Google Cloud Text-to-Speech API. + Converts Firestore documents to audio files stored in Cloud Storage using Cloud Text to Speech. license: Apache-2.0 -sourceUrl: https://github.com/firebase/extensions/tree/master/firestore-translate-text -releaseNotesUrl: https://github.com/firebase/extensions/blob/master/firestore-translate-text/CHANGELOG.md +sourceUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/tree/main/text-to-speech +releaseNotesUrl: https://github.com/GoogleCloudPlatform/firebase-extensions/blob/main/text-to-speech/CHANGELOG.md author: - authorName: Firebase - url: https://firebase.google.com + authorName: Google Cloud + url: https://cloud.google.com/ contributors: - authorName: Invertase diff --git a/firestore-text-to-speech/functions/.gitignore b/text-to-speech/functions/.gitignore similarity index 100% rename from firestore-text-to-speech/functions/.gitignore rename to text-to-speech/functions/.gitignore diff --git a/firestore-text-to-speech/functions/__tests__/__mocks__/index.ts b/text-to-speech/functions/__tests__/__mocks__/index.ts similarity index 100% rename from firestore-text-to-speech/functions/__tests__/__mocks__/index.ts rename to text-to-speech/functions/__tests__/__mocks__/index.ts diff --git a/firestore-text-to-speech/functions/__tests__/functions.test.ts b/text-to-speech/functions/__tests__/functions.test.ts similarity index 100% rename from firestore-text-to-speech/functions/__tests__/functions.test.ts rename to text-to-speech/functions/__tests__/functions.test.ts diff --git a/firestore-text-to-speech/functions/__tests__/helpers.ts b/text-to-speech/functions/__tests__/helpers.ts similarity index 100% rename from firestore-text-to-speech/functions/__tests__/helpers.ts rename to text-to-speech/functions/__tests__/helpers.ts diff --git a/firestore-text-to-speech/functions/__tests__/helpers/setupEnvironment.ts b/text-to-speech/functions/__tests__/helpers/setupEnvironment.ts similarity index 100% rename from firestore-text-to-speech/functions/__tests__/helpers/setupEnvironment.ts rename to text-to-speech/functions/__tests__/helpers/setupEnvironment.ts diff --git a/firestore-text-to-speech/functions/__tests__/jest.setup.ts b/text-to-speech/functions/__tests__/jest.setup.ts similarity index 100% rename from firestore-text-to-speech/functions/__tests__/jest.setup.ts rename to text-to-speech/functions/__tests__/jest.setup.ts diff --git a/firestore-text-to-speech/functions/__tests__/tsconfig.json b/text-to-speech/functions/__tests__/tsconfig.json similarity index 100% rename from firestore-text-to-speech/functions/__tests__/tsconfig.json rename to text-to-speech/functions/__tests__/tsconfig.json diff --git a/firestore-text-to-speech/functions/jest.config.js b/text-to-speech/functions/jest.config.js similarity index 100% rename from firestore-text-to-speech/functions/jest.config.js rename to text-to-speech/functions/jest.config.js diff --git a/firestore-text-to-speech/functions/package.json b/text-to-speech/functions/package.json similarity index 100% rename from firestore-text-to-speech/functions/package.json rename to text-to-speech/functions/package.json diff --git a/firestore-text-to-speech/functions/src/config.ts b/text-to-speech/functions/src/config.ts similarity index 98% rename from firestore-text-to-speech/functions/src/config.ts rename to text-to-speech/functions/src/config.ts index 1753010b..e642eaa2 100644 --- a/firestore-text-to-speech/functions/src/config.ts +++ b/text-to-speech/functions/src/config.ts @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google LLC + * Copyright 2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/firestore-text-to-speech/functions/src/index.ts b/text-to-speech/functions/src/index.ts similarity index 76% rename from firestore-text-to-speech/functions/src/index.ts rename to text-to-speech/functions/src/index.ts index 8ef7f94d..bcbe9e54 100644 --- a/firestore-text-to-speech/functions/src/index.ts +++ b/text-to-speech/functions/src/index.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import * as admin from 'firebase-admin'; import * as functions from 'firebase-functions'; import config from './config'; diff --git a/firestore-text-to-speech/functions/src/logs.ts b/text-to-speech/functions/src/logs.ts similarity index 100% rename from firestore-text-to-speech/functions/src/logs.ts rename to text-to-speech/functions/src/logs.ts diff --git a/text-to-speech/functions/src/types.ts b/text-to-speech/functions/src/types.ts new file mode 100644 index 00000000..396b3bf2 --- /dev/null +++ b/text-to-speech/functions/src/types.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as tts from '@google-cloud/text-to-speech'; + +export type ISynthesizeSpeechRequest = + tts.protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest; +export type ISynthesizeSpeechResponse = + tts.protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse; +export type AudioEncoding = + | tts.protos.google.cloud.texttospeech.v1.AudioEncoding + | 'AUDIO_ENCODING_UNSPECIFIED' + | 'LINEAR16' + | 'MP3' + | 'OGG_OPUS' + | 'MULAW' + | 'ALAW'; +export type SsmlVoiceGender = + tts.protos.google.cloud.texttospeech.v1.SsmlVoiceGender; diff --git a/firestore-text-to-speech/functions/src/util.ts b/text-to-speech/functions/src/util.ts similarity index 64% rename from firestore-text-to-speech/functions/src/util.ts rename to text-to-speech/functions/src/util.ts index fa7311d7..1f54b54c 100644 --- a/firestore-text-to-speech/functions/src/util.ts +++ b/text-to-speech/functions/src/util.ts @@ -1,3 +1,18 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { AudioEncoding, ISynthesizeSpeechRequest, diff --git a/firestore-text-to-speech/functions/tsconfig.json b/text-to-speech/functions/tsconfig.json similarity index 100% rename from firestore-text-to-speech/functions/tsconfig.json rename to text-to-speech/functions/tsconfig.json