diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 5db3ac4..4b211c0 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -211,7 +211,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc case 'polly': vendorLabel = 'aws'; audioData = await synthPolly(createHash, retrieveHash, logger, - {credentials, stats, language, voice, text, engine}); + {credentials, stats, language, voice, text, engine, renderForCaching, disableTtsStreaming}); break; case 'azure': case 'microsoft': @@ -307,9 +307,41 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc } const synthPolly = async(createHash, retrieveHash, logger, - {credentials, stats, language, voice, engine, text}) => { + {credentials, stats, language, voice, engine, text, renderForCaching, disableTtsStreaming}) => { + const {region, accessKeyId, secretAccessKey, roleArn} = credentials; + if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) { + + let params = '{'; + params += `language=${language}`; + params += ',write_cache_file=1'; + params += ',vendor=aws'; + if (accessKeyId && secretAccessKey) { + if (accessKeyId) params += `,accessKeyId=${accessKeyId}`; + if (secretAccessKey) params += `,secretAccessKey=${secretAccessKey}`; + } else if (roleArn) { + const cred = await getAwsAuthToken( + logger, createHash, retrieveHash, + { + region, + roleArn + }); + + if (cred) { + params += `,accessKeyId=${cred.accessKeyId}`; + params += `,secretAccessKey=${cred.secretAccessKey}`; + params += `,sessionToken=${cred.sessionToken}`; + } + } + if (region) params += `,region=${region}`; + params += '}'; + + return { + filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`, + servedFromCache: false, + rtt: 0 + }; + } try { - const {region, accessKeyId, secretAccessKey, roleArn} = credentials; let polly; if (accessKeyId && secretAccessKey) { polly = new PollyClient({ diff --git a/test/synth.js b/test/synth.js index 7cfba4c..fddad81 100644 --- a/test/synth.js +++ b/test/synth.js @@ -185,6 +185,7 @@ test('AWS speech synth tests', async(t) => { language: 'en-US', voice: 'Joey', text: 'This is a test. This is only a test', + renderForCaching: true, }); t.ok(!opts.servedFromCache, `successfully synthesized aws audio to ${opts.filePath}`); @@ -198,6 +199,7 @@ test('AWS speech synth tests', async(t) => { language: 'en-US', voice: 'Joey', text: 'This is a test. This is only a test', + renderForCaching: true, }); t.ok(opts.servedFromCache, `successfully retrieved aws audio from cache ${opts.filePath}`); } catch (err) {