( text = 'Hello Everybody! This is an audio profile optimized sound byte.', outputFile = './resources/phone.mp3', languageCode = 'en-US', ssmlGender = 'FEMALE' )
| 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); |
no test coverage detected