diff --git a/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js b/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js index 9af5442fa..383cf7043 100644 --- a/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js +++ b/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js @@ -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({