- You must have aws-sdk available in the page.
- Get CognitoPoolId which can access Polly.
- Initialize the object with
var msg = new pollyVoiceOver(awsCognitoPoolId);
- use
addVoiceOver
oraddTranslatedVoiceOver
function with desired text. Example:
// With delay of 3 seconds
msg.addVoiceOver('This is the demo about voice over with polly!', 3000);
btn = document.getElementById('button');
btn.addEventListener('click', function() {
msg.addVoiceOver('When we click on this button polly send this request and speaks back to you!');
}, false);
(just keep in mind to use correct lexicon for better accent.)
btn = document.getElementById('button-es');
btn.addEventListener('click', function() {
msg.addTranslatedVoiceOver('This is translated content in spanish!', 'es', 0, {'lexicon': 'Conchita'});
}, false);
There are few configuration options available in script.
- Change the css of caption text:
var css = {'color': 'indianred', 'background': '#fff'};
msg.addVoiceOver('Caption with different CSS!', 10, {'styles': css});
- Destroy the caption after audio play:
msg.addVoiceOver('When we click on this button polly send this request and speaks back to you!', 10, {'hideOnAudioEnd': true});
- Change the voice:
msg.addVoiceOver('When we click on this button polly send this request and speaks back to you!', 10, {'hideOnAudioEnd': true, 'lexicon': 'Brian'});
// See full list of lexicons: https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html#voice