Created
March 23, 2018 17:02
-
-
Save ajb413/b1168e25d6e5a4cf8ce1594131752a0c to your computer and use it in GitHub Desktop.
polly get audio function for AWS demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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