Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created March 23, 2018 17:02
Show Gist options
  • Save ajb413/b1168e25d6e5a4cf8ce1594131752a0c to your computer and use it in GitHub Desktop.
Save ajb413/b1168e25d6e5a4cf8ce1594131752a0c to your computer and use it in GitHub Desktop.
polly get audio function for AWS demo
// Polly Button click event handler from app.js
function (e) {
var _app = this;
if (e.dataset.voiceAudioContent) {
_app.play(e.dataset.voiceAudioContent);
return;
} else {
$.ajax({
method: "POST",
url: pollyFunctionURI,
data: JSON.stringify({
"data": {
"text": e.dataset.text,
"polly": {
"voice": "Matthew",
"format": "mp3",
"location": "text"
}
}
}),
})
.done(function(res) {
e.dataset.voiceAudioContent = 'data:audio/mp3;base64,' + res.polly_sound;
_app.play(e.dataset.voiceAudioContent);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment