| async function send() { |
| let input = document.getElementById("input").value; |
| let response = await ask(input); |
| document.getElementById("botresponse").innerHTML = response; |
| } |
|
|
| function ask(question) { |
| return `Hello! I am MyChatbot, an AI chatbot. How can I assist you today?`; |
| } |
|
|
| function listen() { |
| speechRecognition.start(); |
| } |
|
|
| const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; |
| const speechRecognition = new SpeechRecognition(); |
| speechRecognition.continuous = true; |
| speechRecognition.onresult = function (event) { |
| if (event.results.length > 0) { |
| if (event.results[0].isFinal) { |
| document.getElementById("input").value = event.results[0][0].transcript; |
| } |
| } |
| } |
|
|
| speechRecognition.onend = function () { |
| speechRecognition.start(); |
| } |
|
|
| speechRecognition.start(); |