You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
eliza2018/eliza.responsivevoice.html

107 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style type="text/css">
#wrapper {
display: flex;
flex-direction: column;
position: absolute;
left: 5%; top: 5%; right: 5%; bottom: 5%;
}
#textinput {
width: 100%;
border: none;
background: none;
}
#input {
padding: 2%;
flex: 0 1 auto;
background: aqua;
}
#display {
flex: 1 1 auto;
background: pink;
padding: 2%;
overflow: auto;
}
#display div.msg {
padding-bottom: 0.5em;
}
#display div.human {
color: black;
}
#display div.bot {
color: black;
text-transform: uppercase;
}
#display div.debug {
color: red;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="display">
</div>
<div id="input">
<input type="text" id="textinput" autofocus />
</div>
</div>
<script src="eliza.js"></script>
<script>
function get_json (url, callback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
callback(data);
} else { callback("server error"); }
};
request.onerror = function() { callback("connection error"); };
request.send();
}
get_json("doctor.json", function (rules) {
var input = document.getElementById("textinput"),
output = document.getElementById("display"),
bot = chatbot(rules, true);
function log (msg, kls) {
var d = document.createElement("div");
d.setAttribute("class", "msg " + kls);
d.innerHTML = msg;
display.appendChild(d);
}
function say (msg) {
responsiveVoice.speak(msg)
log(msg, "bot");
// https://responsivevoice.org/api/
display.scrollTop = display.scrollTopMax;
// responsiveVoice.speak("hello world", "UK English Male", {onstart: StartCallback, onend: EndCallback});
}
var voicelist = responsiveVoice.getVoices();
console.log("voicelist", voicelist);
responsiveVoice.setDefaultVoice("US English Female");
input.addEventListener("keypress", function (event) {
if (event.keyCode == 13) {
var text = input.value;
log(text, "user");
say(bot(text), "bot");
input.value = "";
input.focus();
}
});
say(rules.initial);
});
</script>
<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
</body>
</html>