mardi 20 janvier 2015

Unable to call a Javascript class from HTML

Please have a look at the below code


TTSScript.js



function TTS()
{
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();

this.speakText = function()
{
window.speechSynthesis.speak("yohan");
}
}


index.html



<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="/scripts/TTSScript.js"></script>
<script>
function speak()
{
var msg = new SpeechSynthesisUtterance('Hello World');
window.speechSynthesis.speak(msg);
}

function speak2()
{
var TTS = new TTS();
TTS.speakText();
}


</script>
</head>
<body>
<div><button onclick="speak2()">Click me</button></div>
</body>
</html>


Unfortunatly when I click on the button in the html page, what I get is an error. It is below.



Uncaught TypeError: undefined is not a function (13:42:13:817 | error, javascript)
at speak2 (public_html/index.html:23:26)
at onclick (public_html/index.html:31:126)


I am not much familiar with JavaScript, can you please let me know why I am getting this error and how to fix it?


Aucun commentaire:

Enregistrer un commentaire