| 40 | } |
| 41 | |
| 42 | async function synthesizeSsml(ssml, outputFile) { |
| 43 | // [START tts_synthesize_ssml] |
| 44 | const textToSpeech = require('@google-cloud/text-to-speech'); |
| 45 | const fs = require('fs'); |
| 46 | const util = require('util'); |
| 47 | |
| 48 | const client = new textToSpeech.TextToSpeechClient(); |
| 49 | |
| 50 | /** |
| 51 | * TODO(developer): Uncomment the following lines before running the sample. |
| 52 | */ |
| 53 | // const ssml = '<speak>Hello there.</speak>'; |
| 54 | // const outputFile = 'Local path to save audio file to, e.g. output.mp3'; |
| 55 | |
| 56 | const request = { |
| 57 | input: {ssml: ssml}, |
| 58 | voice: {languageCode: 'en-US', ssmlGender: 'FEMALE'}, |
| 59 | audioConfig: {audioEncoding: 'MP3'}, |
| 60 | }; |
| 61 | |
| 62 | const [response] = await client.synthesizeSpeech(request); |
| 63 | const writeFile = util.promisify(fs.writeFile); |
| 64 | await writeFile(outputFile, response.audioContent, 'binary'); |
| 65 | console.log(`Audio content written to file: ${outputFile}`); |
| 66 | // [END tts_synthesize_ssml] |
| 67 | } |
| 68 | |
| 69 | async function synthesizeTextFile(textFile, outputFile) { |
| 70 | // [START tts_synthesize_text_file] |