{"name":"Glossary TTS Reader (Cloud)","key":"glossaryttsreadercloud","version":"1.0.1","instructions":"This is a small html5 audio player that will read aloud the enclosed text block. It works anywhere but mainly in the glossary popup (Uses Cloud Poodll)  ","showatto":"1","showplayers":"0","requirecss":"","requirejs":"","shim":"","defaults":"play=\"fa-volume-up\",background=\"red\",color=\"#fff\",width=\"40\",height=\"40\",defaultvoice=\"Kendra|Justin|Amy|Emma|Russell\"","amd":"1","body":"<button type='button' id='@@AUTOID@@' data-currentsentence=\"0\" class=\"roundmini-audio-player\" style=\"width: @@width@@px; height: @@height@@px; background-color: @@background@@; \tborder-radius: 50%;\" \nonclick=\"\n //FUNCTION fetch polly url\n var fetch_polly_url = function(speaktext, voice, callback) {\n\n                //The REST API we are calling\n                var functionname = 'local_cpapi_fetch_polly_url';\n\n                //fetch the Posturl. We need this.\n                //set up our ajax request\n                var xhr = new XMLHttpRequest();\n                var that = this;\n\n                //set up our handler for the response\n                xhr.onreadystatechange = function (e) {\n                    if (this.readyState === 4) {\n                        if (xhr.status == 200) {\n\n                            //get a yes or forgetit or tryagain\n                            var payload = xhr.responseText;\n                            var payloadobject = JSON.parse(payload);\n                            if (payloadobject) {\n                                //returnCode > 0  indicates an error\n                                if (payloadobject.returnCode > 0) {\n                                    console.log(payloadobject.returnMessage);\n                                    return false;\n                                    //if all good, then lets do the embed\n                                } else if (payloadobject.returnCode === 0){\n                                    var pollyurl = payloadobject.returnMessage;\n                                    callback(pollyurl);\n                                } else {\n                                    console.log('Polly Signed URL Request failed:');\n                                    console.log(payloadobject);\n                                }\n                            } else {\n                                console.log('Polly Signed URL Request something bad happened');\n                            }\n                        } else {\n                            console.log('Polly Signed URL Request Not 200 response:' + xhr.status);\n                        }\n                    }\n                };\n\n                //make our request\n                var xhrparams = 'wstoken=' + '@@CLOUDPOODLLTOKEN@@'\n                + '&wsfunction=' + functionname\n                + '&moodlewsrestformat=' + 'json'\n                + '&text=' + encodeURIComponent(speaktext)\n                + '&texttype=text'\n                + '&voice=' + voice\n                + '&appid=' + 'filter_poodll'\n                + '&owner=poodll'\n                + '&region=useast1';\n\n                var serverurl = 'https://cloud.poodll.com' + '/webservice/rest/server.php';\n                xhr.open('POST', serverurl, true);\n                xhr.setRequestHeader('Cache-Control', 'no-cache');\n                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n                xhr.send(xhrparams);\n        };\n\n//fetch DOM elements that we care about\nvar thebutton =document.getElementById('@@AUTOID@@');\n  var theaudio =document.getElementById('@@AUTOID@@_player');\n  var theinnerdiv =document.getElementById('@@AUTOID@@_innerdiv');\n\n  //if we are playing, then stop\n  if(!theaudio.paused){\n   theaudio.pause();\n   theaudio.currentTime = 0;\n   return;\n}\n       \n//if we have the Polly URL, we do no need to get it again\nif(theaudio.getAttribute('src') == undefined){\n      fetch_polly_url(theinnerdiv.textContent,'@@defaultvoice@@',function(pollyurl){\n           theaudio.setAttribute('src',pollyurl);\n           theaudio.play();  \n       });     \n}else{\n    theaudio.play();    \n}\n\n\n\n\">\n\t<audio id='@@AUTOID@@_player' class=\"roundminiaudio nomediaplugin\">\n\t</audio>\n\t<i class=\"fa fa-volume-up\" aria-hidden=\"true\" style=\"color:@@color@@\"></i>\n</button>\n\n<!-- @@CLOUDPOODLLTOKEN@@ -->\n\n<div id='@@AUTOID@@_textblock' >\n<div id='@@AUTOID@@_innerdiv' class='tbr_innerdiv'>","bodyend":"</div>\n</div>","script":"","style":"button.roundmini-audio-player{\n\tborder: none;\n\tcolor: #fff;\n}\nbutton.roundmini-audio-player .fa{\n     font-size: 28px;\n}\n.activesentence {\n    background: #c5efcf;\n   /* font-weight: bold; */\n}","dataset":"","datasetvars":"","alternate":"","alternateend":""}