Skip to content

Commit

Permalink
Merge pull request #2245 from dennisrijsdijk/v5-lexicon-fix
Browse files Browse the repository at this point in the history
fix: amazon polly effects from before update not working
  • Loading branch information
zunderscore committed Sep 22, 2023
2 parents a5d5ded + 66c5289 commit 855fea1
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,30 +515,36 @@ const playSound = {
effect.text = effect.text.replace("&", "&");
}

let listLexiconsResponse = null;
let lexicons = [];
let lexiconError;

do {
try {
const listLexiconsCommand = new ListLexiconsCommand({
NextToken: listLexiconsResponse ? listLexiconsResponse.NextToken : undefined
});
listLexiconsResponse = await polly.send(listLexiconsCommand);
listLexiconsResponse.Lexicons.forEach(lexicon => lexicons.push(lexicon.Name));
} catch (e) {
lexicons = [];
lexiconError = e;
listLexiconsResponse = null;
break;
}
} while (listLexiconsResponse && listLexiconsResponse.NextToken);

if (lexiconError) {
logger.error("Error while trying to fetch lexicons before speech synthesis, proceeding without lexicons.");
if (effect.lexicons == null) {
effect.lexicons = [];
} else {
effect.lexicons = effect.lexicons.filter(lexicon => lexicons.includes(lexicon));
}

if (effect.lexicons.length !== 0) {
let listLexiconsResponse = null;
let lexicons = [];
let lexiconError;

do {
try {
const listLexiconsCommand = new ListLexiconsCommand({
NextToken: listLexiconsResponse ? listLexiconsResponse.NextToken : undefined
});
listLexiconsResponse = await polly.send(listLexiconsCommand);
listLexiconsResponse.Lexicons.forEach(lexicon => lexicons.push(lexicon.Name));
} catch (e) {
lexicons = [];
lexiconError = e;
listLexiconsResponse = null;
break;
}
} while (listLexiconsResponse && listLexiconsResponse.NextToken);

if (lexiconError) {
logger.error("Error while trying to fetch lexicons before speech synthesis, proceeding without lexicons.");
effect.lexicons = [];
} else {
effect.lexicons = effect.lexicons.filter(lexicon => lexicons.includes(lexicon));
}
}

const synthSpeechCommand = new SynthesizeSpeechCommand({
Expand Down

0 comments on commit 855fea1

Please sign in to comment.