Skip to content

Commit 9910bb9

Browse files
authored
Merge pull request #2872 from GoogleCloudPlatform/nodejs-text-to-speech-migration
migrate code from googleapis/nodejs-text-to-speech
2 parents 089dbe2 + e0e9bdb commit 9910bb9

22 files changed

+833
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: texttospeech
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'texttospeech/**'
8+
pull_request:
9+
paths:
10+
- 'texttospeech/**'
11+
pull_request_target:
12+
types: [labeled]
13+
paths:
14+
- 'texttospeech/**'
15+
schedule:
16+
- cron: '0 0 * * 0'
17+
jobs:
18+
test:
19+
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 60
22+
permissions:
23+
contents: 'write'
24+
pull-requests: 'write'
25+
id-token: 'write'
26+
steps:
27+
- uses: actions/checkout@v3.1.0
28+
with:
29+
ref: ${{github.event.pull_request.head.sha}}
30+
- uses: 'google-github-actions/auth@v1.0.0'
31+
with:
32+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
33+
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com'
34+
create_credentials_file: 'true'
35+
access_token_lifetime: 600s
36+
- uses: actions/setup-node@v3.5.1
37+
with:
38+
node-version: 16
39+
- run: npm install
40+
working-directory: texttospeech
41+
- run: npm test
42+
working-directory: texttospeech
43+
env:
44+
MOCHA_REPORTER_SUITENAME: texttospeech
45+
MOCHA_REPORTER_OUTPUT: texttospeech_sponge_log.xml
46+
MOCHA_REPORTER: xunit
47+
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
48+
uses: actions/github-script@v6
49+
with:
50+
github-token: ${{ secrets.GITHUB_TOKEN }}
51+
script: |
52+
try {
53+
await github.rest.issues.removeLabel({
54+
name: 'actions:force-run',
55+
owner: 'GoogleCloudPlatform',
56+
repo: 'nodejs-docs-samples',
57+
issue_number: context.payload.pull_request.number
58+
});
59+
} catch (e) {
60+
if (!e.message.includes('Label does not exist')) {
61+
throw e;
62+
}
63+
}
64+
- if: ${{ github.event_name == 'schedule'}}
65+
run: |
66+
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
67+
chmod +x ./flakybot
68+
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}

.github/workflows/workflows.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"scheduler",
6262
"speech",
6363
"talent",
64+
"texttospeech",
6465
"translate",
6566
"video-intelligence",
6667
"contact-center-insights",

CODEOWNERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ monitoring/opencensus @GoogleCloudPlatform/nodejs-samples-reviewers
4242

4343
# Data & AI
4444
contact-center-insights @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
45+
datalabeling @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
46+
document-ai @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
47+
mediatranslation @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
48+
speech @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
4549
talent @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
50+
texttospeech @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
51+
translate @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
52+
video-intelligence @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
4653

4754
# DEE-PO
4855
error-reporting @GoogleCloudPlatform/dee-platform-ops @GoogleCloudPlatform/nodejs-samples-reviewers

texttospeech/.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
rules:
3+
no-console: off

texttospeech/audioProfile.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2017 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
async function main(
17+
text = 'Hello Everybody! This is an audio profile optimized sound byte.',
18+
outputFile = './resources/phone.mp3',
19+
languageCode = 'en-US',
20+
ssmlGender = 'FEMALE'
21+
) {
22+
//[START tts_synthesize_text_audio_profile]
23+
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const text = 'Text you want to vocalize';
28+
// const outputFile = 'YOUR_OUTPUT_FILE_LOCAtION;
29+
// const languageCode = 'LANGUAGE_CODE_FOR_OUTPUT';
30+
// const ssmlGender = 'SSML_GENDER_OF_SPEAKER';
31+
32+
// Imports the Google Cloud client library
33+
const speech = require('@google-cloud/text-to-speech');
34+
const fs = require('fs');
35+
const util = require('util');
36+
37+
// Creates a client
38+
const client = new speech.TextToSpeechClient();
39+
40+
async function synthesizeWithEffectsProfile() {
41+
// Add one or more effects profiles to array.
42+
// Refer to documentation for more details:
43+
// https://cloud.google.com/text-to-speech/docs/audio-profiles
44+
const effectsProfileId = ['telephony-class-application'];
45+
46+
const request = {
47+
input: {text: text},
48+
voice: {languageCode: languageCode, ssmlGender: ssmlGender},
49+
audioConfig: {audioEncoding: 'MP3', effectsProfileId: effectsProfileId},
50+
};
51+
52+
const [response] = await client.synthesizeSpeech(request);
53+
const writeFile = util.promisify(fs.writeFile);
54+
await writeFile(outputFile, response.audioContent, 'binary');
55+
console.log(`Audio content written to file: ${outputFile}`);
56+
}
57+
// [END tts_synthesize_text_audio_profile]
58+
59+
synthesizeWithEffectsProfile();
60+
}
61+
62+
main(...process.argv.slice(2)).catch(err => {
63+
console.error(err);
64+
process.exitCode = 1;
65+
});

texttospeech/hello.mp3

8.63 KB
Binary file not shown.

texttospeech/listVoices.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function listVoices() {
18+
// [START tts_list_voices]
19+
const textToSpeech = require('@google-cloud/text-to-speech');
20+
21+
const client = new textToSpeech.TextToSpeechClient();
22+
23+
const [result] = await client.listVoices({});
24+
const voices = result.voices;
25+
26+
console.log('Voices:');
27+
voices.forEach(voice => {
28+
console.log(`Name: ${voice.name}`);
29+
console.log(` SSML Voice Gender: ${voice.ssmlGender}`);
30+
console.log(` Natural Sample Rate Hertz: ${voice.naturalSampleRateHertz}`);
31+
console.log(' Supported languages:');
32+
voice.languageCodes.forEach(languageCode => {
33+
console.log(` ${languageCode}`);
34+
});
35+
});
36+
// [END tts_list_voices]
37+
}
38+
39+
async function main() {
40+
require(`yargs`) // eslint-disable-line
41+
.demand(1)
42+
.command('list-voices', 'List supported voices.', {}, () => listVoices())
43+
.example('node $0 list-voices')
44+
.wrap(120)
45+
.recommendCommands()
46+
.epilogue(
47+
'For more information, see https://cloud.google.com/text-to-speech/docs'
48+
)
49+
.help()
50+
.strict().argv;
51+
}
52+
53+
main().catch(console.error);

texttospeech/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nodejs-docs-samples-text-to-speech",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"author": "Google Inc.",
6+
"repository": "googleapis/nodejs-text-to-speech",
7+
"files": [
8+
"*.js"
9+
],
10+
"engines": {
11+
"node": ">=12.0.0"
12+
},
13+
"scripts": {
14+
"test": "mocha --timeout=60000"
15+
},
16+
"dependencies": {
17+
"@google-cloud/text-to-speech": "^4.0.4",
18+
"yargs": "^16.0.0"
19+
},
20+
"devDependencies": {
21+
"chai": "^4.2.0",
22+
"mocha": "^8.0.0"
23+
}
24+
}

texttospeech/quickstart.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
function main() {
18+
// [START tts_quickstart]
19+
// Imports the Google Cloud client library
20+
const textToSpeech = require('@google-cloud/text-to-speech');
21+
22+
// Import other required libraries
23+
const fs = require('fs');
24+
const util = require('util');
25+
// Creates a client
26+
const client = new textToSpeech.TextToSpeechClient();
27+
async function quickStart() {
28+
// The text to synthesize
29+
const text = 'hello, world!';
30+
31+
// Construct the request
32+
const request = {
33+
input: {text: text},
34+
// Select the language and SSML voice gender (optional)
35+
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
36+
// select the type of audio encoding
37+
audioConfig: {audioEncoding: 'MP3'},
38+
};
39+
40+
// Performs the text-to-speech request
41+
const [response] = await client.synthesizeSpeech(request);
42+
// Write the binary audio content to a local file
43+
const writeFile = util.promisify(fs.writeFile);
44+
await writeFile('output.mp3', response.audioContent, 'binary');
45+
console.log('Audio content written to file: output.mp3');
46+
}
47+
quickStart();
48+
// [END tts_quickstart]
49+
}
50+
51+
main(...process.argv.slice(2));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<speak>123 Street Ln, Small Town, IL 12345 USA
2+
<break time="2s"/>1 Jenny St &amp; Number St, Tutone City, CA 86753
3+
<break time="2s"/>1 Piazza del Fibonacci, 12358 Pisa, Italy
4+
<break time="2s"/></speak>

0 commit comments

Comments
 (0)