Shresthh03 commited on
Commit
7a4aa29
·
verified ·
1 Parent(s): 73f39c5

Update everything.

Browse files

Just update everything and make it final launch ready.

Files changed (1) hide show
  1. index.html +74 -6
index.html CHANGED
@@ -7,7 +7,22 @@
7
  </head>
8
  <body class="transition-all duration-700 bg-gradient-to-br from-yellow-200 to-yellow-400 text-gray-800 flex flex-col items-center justify-center min-h-screen p-4" id="bg">
9
  <div class="max-w-md w-full bg-white bg-opacity-70 rounded-3xl shadow-lg p-6 text-center">
10
- <h1 class="text-2xl font-bold mb-4 text-gray-900">🌿 Serenity AI — Your Caring Companion</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  <div id="chat-box" class="h-64 overflow-y-auto mb-4 border rounded-xl p-3 bg-gray-50 text-left"></div>
13
 
@@ -28,6 +43,16 @@
28
  recognition.lang = "en-US";
29
  recognition.continuous = false;
30
 
 
 
 
 
 
 
 
 
 
 
31
  function appendMessage(sender, text) {
32
  const div = document.createElement("div");
33
  div.className = sender === "user" ? "text-right text-blue-700 my-2" : "text-left text-gray-800 my-2";
@@ -50,17 +75,55 @@
50
  const data = await response.json();
51
 
52
  appendMessage("bot", data.reply);
53
- speakText(data.reply);
54
  changeBackground(data.emotion);
55
  }
56
 
57
- function speakText(text) {
58
  synth.cancel();
59
  const utter = new SpeechSynthesisUtterance(text);
60
- utter.pitch = 0.7;
61
- utter.rate = 0.9;
 
 
 
62
  utter.volume = 1;
63
- utter.voice = synth.getVoices().find(v => v.name.toLowerCase().includes("male") || v.name.toLowerCase().includes("microsoft")) || synth.getVoices()[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  synth.speak(utter);
65
  }
66
 
@@ -90,6 +153,11 @@
90
  }
91
  bg.className = `transition-all duration-700 bg-gradient-to-br ${gradient} flex flex-col items-center justify-center min-h-screen p-4`;
92
  }
 
 
 
 
 
93
  </script>
94
  </body>
95
  </html>
 
7
  </head>
8
  <body class="transition-all duration-700 bg-gradient-to-br from-yellow-200 to-yellow-400 text-gray-800 flex flex-col items-center justify-center min-h-screen p-4" id="bg">
9
  <div class="max-w-md w-full bg-white bg-opacity-70 rounded-3xl shadow-lg p-6 text-center">
10
+ <h1 class="text-2xl font-bold mb-3 text-gray-900">🌿 Serenity AI — Your Caring Companion</h1>
11
+
12
+ <!-- Voice Selector -->
13
+ <div class="mb-4">
14
+ <label for="voiceSelect" class="block text-gray-700 font-semibold mb-1">🎧 Choose Serenity's Voice:</label>
15
+ <select id="voiceSelect" class="w-full p-2 border rounded-lg bg-white">
16
+ <option value="calm_male">Calm Male</option>
17
+ <option value="deep_male">Deep Male</option>
18
+ <option value="soothing_male">Soothing Male</option>
19
+ <option value="gentle_female">Gentle Loving Female</option>
20
+ <option value="feminine_female">Feminine Female</option>
21
+ <option value="deep_female">Deep & Soar Female</option>
22
+ <option value="soothing_female">Soothing Female</option>
23
+ <option value="neutral">Neutral Soothing Voice</option>
24
+ </select>
25
+ </div>
26
 
27
  <div id="chat-box" class="h-64 overflow-y-auto mb-4 border rounded-xl p-3 bg-gray-50 text-left"></div>
28
 
 
43
  recognition.lang = "en-US";
44
  recognition.continuous = false;
45
 
46
+ // Load saved voice preference if available
47
+ let selectedVoiceProfile = localStorage.getItem("voiceProfile") || "calm_male";
48
+ document.getElementById("voiceSelect").value = selectedVoiceProfile;
49
+
50
+ // Change voice preference dynamically
51
+ document.getElementById("voiceSelect").addEventListener("change", (e) => {
52
+ selectedVoiceProfile = e.target.value;
53
+ localStorage.setItem("voiceProfile", selectedVoiceProfile);
54
+ });
55
+
56
  function appendMessage(sender, text) {
57
  const div = document.createElement("div");
58
  div.className = sender === "user" ? "text-right text-blue-700 my-2" : "text-left text-gray-800 my-2";
 
75
  const data = await response.json();
76
 
77
  appendMessage("bot", data.reply);
78
+ speakText(data.reply, selectedVoiceProfile);
79
  changeBackground(data.emotion);
80
  }
81
 
82
+ function speakText(text, voiceProfile) {
83
  synth.cancel();
84
  const utter = new SpeechSynthesisUtterance(text);
85
+ const voices = synth.getVoices();
86
+
87
+ // Default values
88
+ utter.pitch = 1;
89
+ utter.rate = 1;
90
  utter.volume = 1;
91
+
92
+ // Apply styles based on voice profile
93
+ switch (voiceProfile) {
94
+ case "calm_male":
95
+ utter.pitch = 0.8; utter.rate = 0.95;
96
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("male")) || voices[0];
97
+ break;
98
+ case "deep_male":
99
+ utter.pitch = 0.6; utter.rate = 0.9;
100
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("microsoft") && v.name.toLowerCase().includes("david")) || voices[0];
101
+ break;
102
+ case "soothing_male":
103
+ utter.pitch = 0.9; utter.rate = 0.85;
104
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("male")) || voices[0];
105
+ break;
106
+ case "gentle_female":
107
+ utter.pitch = 1.3; utter.rate = 0.95;
108
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("female")) || voices[0];
109
+ break;
110
+ case "feminine_female":
111
+ utter.pitch = 1.5; utter.rate = 1;
112
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("female")) || voices[0];
113
+ break;
114
+ case "deep_female":
115
+ utter.pitch = 0.9; utter.rate = 0.9;
116
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("female")) || voices[0];
117
+ break;
118
+ case "soothing_female":
119
+ utter.pitch = 1.2; utter.rate = 0.85;
120
+ utter.voice = voices.find(v => v.name.toLowerCase().includes("female")) || voices[0];
121
+ break;
122
+ case "neutral":
123
+ utter.pitch = 1; utter.rate = 1; utter.voice = voices[0];
124
+ break;
125
+ }
126
+
127
  synth.speak(utter);
128
  }
129
 
 
153
  }
154
  bg.className = `transition-all duration-700 bg-gradient-to-br ${gradient} flex flex-col items-center justify-center min-h-screen p-4`;
155
  }
156
+
157
+ // Reload available voices properly when browser loads them
158
+ if (speechSynthesis.onvoiceschanged !== undefined) {
159
+ speechSynthesis.onvoiceschanged = () => {};
160
+ }
161
  </script>
162
  </body>
163
  </html>