forked from ShubhMittal44/Chat-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathj8.js
117 lines (105 loc) · 9.73 KB
/
j8.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const voice = document.querySelector(".voice");
const voice2text = document.querySelector(".voice2text");
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recorder = new SpeechRecognition();
function addHumanText(text) {
const chatContainer = document.createElement("div");
chatContainer.classList.add("chat-container");
const chatBox = document.createElement("p");
chatBox.classList.add("voice2text");
const chatText = document.createTextNode(text);
chatBox.appendChild(chatText);
chatContainer.appendChild(chatBox);
return chatContainer;
}
function addBotText(text) {
const chatContainer1 = document.createElement("div");
chatContainer1.classList.add("chat-container");
chatContainer1.classList.add("darker");
const chatBox1 = document.createElement("p");
chatBox1.classList.add("voice2text");
const chatText1 = document.createTextNode(text);
chatBox1.appendChild(chatText1);
chatContainer1.appendChild(chatBox1);
return chatContainer1;
}
function botVoice(message) {
const speech = new SpeechSynthesisUtterance();
speech.text = "Sorry, I did not understand that.";
if (message.includes('how are you')) {
speech.text = "I am fine, thanks. How are you?";
}
if (message.includes('hello')) {
speech.text = "Hiiii!! Welcome to our Website";
}
if (message.includes('good')) {
speech.text = "That's Nice";
}
if (message.includes('fine')) {
speech.text = "Nice to hear that. How can I assist you today?";
}
if (message.includes('weather')) {
speech.text = "Of course. Where are you currently?";
}
if (message.includes('one')) {
speech.text = "What is Your Query?"
}
if (message.includes('1')) {
speech.text = "What is Your Query?"
}
if (message.includes('apple')) {
speech.text = "Like most fruit-producing plants, apples want as much sun as they can get to grow their best. They’ll need at least six hours of sun each day, preferably in a location where they are spared the worst of the summertime late-afternoon sun."
}
if (message.includes('mango')) {
speech.text = "You can plant mango trees year-round, but the best time time to plant a mango tree is in autumn. Start by digging a hole and incorporating added organic matter such as compost or rotted cow manure. After planting the sapling to the same depth as its original container, form a mound around it to improve drainage and encourage establishment. Water it well and mulch with hay."
}
if (message.includes('Blood Pressure')) {
speech.text = "Eat more fruits, vegetables, and low-fat dairy foods. Cut back on foods that are high in saturated fat, cholesterol, and trans fats. Eat more whole-grain foods, fish, poultry, and nuts,Limit sodium, sweets, sugary drinks, and red meats.Drink low-fat or skim dairy products any time you would normally use full-fat or cream. Limit meat to 6 ounces a day. Make some meals vegetarian. Add more vegetables and dry beans to your diet. Instead of snacking on chips or sweets, eat unsalted pretzels or nuts, raisins, low-fat and fat-free yogurt, frozen yogurt, unsalted plain popcorn with no butter, and raw vegetables.";
}
if (message.includes('BP')) {
speech.text = "Eat more fruits, vegetables, and low-fat dairy foods. Cut back on foods that are high in saturated fat, cholesterol, and trans fats. Eat more whole-grain foods, fish, poultry, and nuts,Limit sodium, sweets, sugary drinks, and red meats.Drink low-fat or skim dairy products any time you would normally use full-fat or cream. Limit meat to 6 ounces a day. Make some meals vegetarian. Add more vegetables and dry beans to your diet. Instead of snacking on chips or sweets, eat unsalted pretzels or nuts, raisins, low-fat and fat-free yogurt, frozen yogurt, unsalted plain popcorn with no butter, and raw vegetables.";
}
if (message.includes('two')) {
speech.text = "Eat more fruits, vegetables, and low-fat dairy foods. Cut back on foods that are high in saturated fat, cholesterol, and trans fats. Eat more whole-grain foods, fish, poultry, and nuts,Limit sodium, sweets, sugary drinks, and red meats.Drink low-fat or skim dairy products any time you would normally use full-fat or cream. Limit meat to 6 ounces a day. Make some meals vegetarian. Add more vegetables and dry beans to your diet. Instead of snacking on chips or sweets, eat unsalted pretzels or nuts, raisins, low-fat and fat-free yogurt, frozen yogurt, unsalted plain popcorn with no butter, and raw vegetables.";
}
if (message.includes('three')) {
speech.text = "plenty of fruit and vegetables — aim for at least 5 portions of vegetables and 2 portions of fruit a day.some bread, rice, potatoes, pasta and other starchy foods — choose wholegrain varieties if you can.some milk and dairy foods-some meat, fish, eggs, beans and other non-dairy sources of protein — try to eat at least 2 portions of fish a week, including a portion of oily fish. just a small amount of foods and drinks that are high in fat or sugar";
}
if (message.includes('above60')) {
speech.text = "plenty of fruit and vegetables — aim for at least 5 portions of vegetables and 2 portions of fruit a day.some bread, rice, potatoes, pasta and other starchy foods — choose wholegrain varieties if you can.some milk and dairy foods-some meat, fish, eggs, beans and other non-dairy sources of protein — try to eat at least 2 portions of fish a week, including a portion of oily fish. just a small amount of foods and drinks that are high in fat or sugar";
}
if (message.includes('aged')) {
speech.text = "plenty of fruit and vegetables — aim for at least 5 portions of vegetables and 2 portions of fruit a day.some bread, rice, potatoes, pasta and other starchy foods — choose wholegrain varieties if you can.some milk and dairy foods-some meat, fish, eggs, beans and other non-dairy sources of protein — try to eat at least 2 portions of fish a week, including a portion of oily fish. just a small amount of foods and drinks that are high in fat or sugar";
}
if (message.includes('Diabetes')) {
speech.text = "Enjoy having regular meals with proper portion sizes. Your healthcare professional can help you learn to make healthy food choices and proper portion sizes.Eat a variety of nutrient-rich foods in each meal, including healthy fats, lean meats or proteins, whole grains and low-fat dairy in appropriate portion sizes. Choose fiber-rich foods, such as fruits, vegetables and whole grains (bran cereals, whole wheat pasta, brown rice) as often as possible.Try alternatives to meat, such as lentils, beans or tofu. Choose calorie-free liquids, such as unsweetened tea, coffee or water. Choose sugar substitutes.Choose lower-salt options.";
}
if (message.includes('four')) {
speech.text = "Enjoy having regular meals with proper portion sizes. Your healthcare professional can help you learn to make healthy food choices and proper portion sizes.Eat a variety of nutrient-rich foods in each meal, including healthy fats, lean meats or proteins, whole grains and low-fat dairy in appropriate portion sizes. Choose fiber-rich foods, such as fruits, vegetables and whole grains (bran cereals, whole wheat pasta, brown rice) as often as possible.Try alternatives to meat, such as lentils, beans or tofu. Choose calorie-free liquids, such as unsweetened tea, coffee or water. Choose sugar substitutes.Choose lower-salt options.";
}
if (message.includes('Pregnanacy')) {
speech.text = "A healthy diet is high in vegetables (five serves daily), fruit (two serves per day), nuts, seeds, fish (up to three servings per week) and other sources of omega-3 foods such as flax or chia seeds, low-fat dairy food, proteins such as legumes and eggs, and a variety of wholegrains such as rice (brown, basmati, doongara), traditional rolled oats, buckwheat flour, wholegrain breads (rye, essene, spelt, kamut), wholemeal pasta, couscous, millet or amaranth. Lean meat (red meat or chicken) is an important source of iron and protein, especially for women with heavy periods. Avoid saturated fats such as butter, cream, bacon and potato chips; limit salt and caffeine. Drink more water and herbal teas such as chamomile.";
}
if (message.includes('five')) {
speech.text = "A healthy diet is high in vegetables (five serves daily), fruit (two serves per day), nuts, seeds, fish (up to three servings per week) and other sources of omega-3 foods such as flax or chia seeds, low-fat dairy food, proteins such as legumes and eggs, and a variety of wholegrains such as rice (brown, basmati, doongara), traditional rolled oats, buckwheat flour, wholegrain breads (rye, essene, spelt, kamut), wholemeal pasta, couscous, millet or amaranth. Lean meat (red meat or chicken) is an important source of iron and protein, especially for women with heavy periods. Avoid saturated fats such as butter, cream, bacon and potato chips; limit salt and caffeine. Drink more water and herbal teas such as chamomile.";
}
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
var element = document.getElementById("container");
element.appendChild(addBotText(speech.text));
}
recorder.onstart = () => {
console.log('Voice activated');
};
recorder.onresult = (event) => {
const resultIndex = event.resultIndex;
const transcript = event.results[resultIndex][0].transcript;
var element = document.getElementById("container");
element.appendChild(addHumanText(transcript));
botVoice(transcript);
};
voice.addEventListener('click', () =>{
recorder.start();
});