update get aws voices

This commit is contained in:
Quan HL
2024-04-22 16:19:04 +07:00
parent 8a5c5c1966
commit b4aad7991b

View File

@@ -6,6 +6,7 @@ const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const ttsGoogle = require('@google-cloud/text-to-speech');
const { PollyClient, DescribeVoicesCommand } = require('@aws-sdk/client-polly');
const { STSClient, AssumeRoleCommand } = require('@aws-sdk/client-sts');
const getIbmVoices = async(client, logger, credentials) => {
const {tts_region, tts_api_key} = credentials;
@@ -89,14 +90,30 @@ const getGoogleVoices = async(_client, logger, credentials) => {
const getAwsVoices = async(_client, logger, credentials) => {
try {
const {region, accessKeyId, secretAccessKey} = credentials;
const client = new PollyClient({
region,
credentials: {
accessKeyId,
secretAccessKey
}
});
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
let client = null;
if (accessKeyId && secretAccessKey) {
client = new PollyClient({
region,
credentials: {
accessKeyId,
secretAccessKey
}
});
} else if (roleArn) {
const stsClient = new STSClient({ region});
const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz Speech' };
const command = new AssumeRoleCommand(roleToAssume);
const response = await stsClient.send(command);
const assumedRoleCreds = response.Credentials;
client = new PollyClient({
region,
credentials: assumedRoleCreds,
});
} else {
throw new Error('Missing Polly credential');
}
const command = new DescribeVoicesCommand({});
const response = await client.send(command);
return response;