mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
Merge pull request #123 from jambonz/feat/mod_aws_tts
support mod_aws_tts
This commit is contained in:
@@ -211,7 +211,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|||||||
case 'polly':
|
case 'polly':
|
||||||
vendorLabel = 'aws';
|
vendorLabel = 'aws';
|
||||||
audioData = await synthPolly(createHash, retrieveHash, logger,
|
audioData = await synthPolly(createHash, retrieveHash, logger,
|
||||||
{credentials, stats, language, voice, text, engine});
|
{credentials, stats, language, voice, text, engine, renderForCaching, disableTtsStreaming});
|
||||||
break;
|
break;
|
||||||
case 'azure':
|
case 'azure':
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
@@ -307,9 +307,41 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const synthPolly = async(createHash, retrieveHash, logger,
|
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 {
|
try {
|
||||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
|
||||||
let polly;
|
let polly;
|
||||||
if (accessKeyId && secretAccessKey) {
|
if (accessKeyId && secretAccessKey) {
|
||||||
polly = new PollyClient({
|
polly = new PollyClient({
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ test('AWS speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'Joey',
|
voice: 'Joey',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
|
renderForCaching: true,
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized aws audio to ${opts.filePath}`);
|
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',
|
language: 'en-US',
|
||||||
voice: 'Joey',
|
voice: 'Joey',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
|
renderForCaching: true,
|
||||||
});
|
});
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved aws audio from cache ${opts.filePath}`);
|
t.ok(opts.servedFromCache, `successfully retrieved aws audio from cache ${opts.filePath}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user