mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-01-25 02:08:26 +00:00
update get aws voices
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user