AWS Polly Reads the Yijing Ball Z

Talk to me Shenron!

<div class="navbar-end"> 
<a class="navbar-item button is-small is-warning readpolly">
Talk to me Shenron!</a> </div>
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';

AWS.config.credentials = new AWS.Credentials("INSERT_ACCESS_ID__HERE", "INSERT_SECRET_ACCESS_KEY_HERE");

var polly = new AWS.Polly();
function doSynthesize(text) {
var pollyParams = {
OutputFormat: "mp3",
SampleRate: "8000",
Text: text,
TextType: "text",
VoiceId: "Joanna"
};

polly.synthesizeSpeech(pollyParams, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
alert("Error calling Amazon Polly. " + err.message);
}
else {
var uInt8Array = new Uint8Array(data.AudioStream);
var arrayBuffer = uInt8Array.buffer;
var blob = new Blob([arrayBuffer]);
var url = URL.createObjectURL(blob);

audioElement = new Audio([url]);
audioElement.play();
}
});
}
const pollyBtn = document.querySelector(".readpolly")

pollyBtn.addEventListener("click", function(){
// all our text is inside of main.content, so we grab it all
const pollyText = document.querySelector("main.content").innerText
doSynthesize(pollyText)
})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store