Merge pull request #123 from jambonz/feat/mod_aws_tts

support mod_aws_tts
This commit is contained in:
Dave Horton
2025-08-14 08:16:32 -04:00
committed by GitHub
2 changed files with 37 additions and 3 deletions

View File

@@ -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({

View File

@@ -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) {