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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Delta AI Voice & Text Chat</title>
|
7 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
|
8 |
+
<style>
|
9 |
+
* {
|
10 |
+
box-sizing: border-box;
|
11 |
+
margin: 0;
|
12 |
+
padding: 0;
|
13 |
+
font-family: 'Inter', sans-serif;
|
14 |
+
}
|
15 |
+
|
16 |
+
body {
|
17 |
+
background: linear-gradient(135deg, #dbeafe, #f0f9ff);
|
18 |
+
color: #333;
|
19 |
+
min-height: 100vh;
|
20 |
+
display: flex;
|
21 |
+
flex-direction: column;
|
22 |
+
align-items: center;
|
23 |
+
justify-content: flex-start;
|
24 |
+
padding: 20px;
|
25 |
+
}
|
26 |
+
|
27 |
+
#header {
|
28 |
+
width: 100%;
|
29 |
+
text-align: center;
|
30 |
+
background-color: #3b82f6;
|
31 |
+
color: white;
|
32 |
+
padding: 15px 0;
|
33 |
+
font-size: 24px;
|
34 |
+
font-weight: 600;
|
35 |
+
border-radius: 12px;
|
36 |
+
margin-bottom: 20px;
|
37 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
38 |
+
}
|
39 |
+
|
40 |
+
#chatbox {
|
41 |
+
width: 100%;
|
42 |
+
max-width: 800px;
|
43 |
+
background: #ffffffd4;
|
44 |
+
backdrop-filter: blur(8px);
|
45 |
+
border-radius: 16px;
|
46 |
+
padding: 25px;
|
47 |
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
|
48 |
+
}
|
49 |
+
|
50 |
+
#chatbox h1 {
|
51 |
+
font-size: 28px;
|
52 |
+
margin-bottom: 20px;
|
53 |
+
color: #1e3a8a;
|
54 |
+
}
|
55 |
+
|
56 |
+
#output {
|
57 |
+
height: 300px;
|
58 |
+
overflow-y: auto;
|
59 |
+
padding: 15px;
|
60 |
+
background-color: #f9fafb;
|
61 |
+
border-radius: 12px;
|
62 |
+
border: 1px solid #e5e7eb;
|
63 |
+
margin-bottom: 20px;
|
64 |
+
}
|
65 |
+
|
66 |
+
.input-row {
|
67 |
+
display: flex;
|
68 |
+
gap: 10px;
|
69 |
+
}
|
70 |
+
|
71 |
+
#userInput {
|
72 |
+
flex: 1;
|
73 |
+
padding: 12px 14px;
|
74 |
+
border-radius: 10px;
|
75 |
+
border: 1px solid #d1d5db;
|
76 |
+
font-size: 16px;
|
77 |
+
background-color: #fff;
|
78 |
+
transition: 0.3s ease;
|
79 |
+
}
|
80 |
+
|
81 |
+
#userInput:focus {
|
82 |
+
outline: none;
|
83 |
+
border-color: #60a5fa;
|
84 |
+
box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
|
85 |
+
}
|
86 |
+
|
87 |
+
#submitBtn, #micBtn {
|
88 |
+
padding: 12px;
|
89 |
+
border: none;
|
90 |
+
border-radius: 10px;
|
91 |
+
background-color: #3b82f6;
|
92 |
+
color: white;
|
93 |
+
font-size: 18px;
|
94 |
+
font-weight: 600;
|
95 |
+
cursor: pointer;
|
96 |
+
transition: background-color 0.3s ease;
|
97 |
+
}
|
98 |
+
|
99 |
+
#submitBtn:hover, #micBtn:hover {
|
100 |
+
background-color: #2563eb;
|
101 |
+
}
|
102 |
+
|
103 |
+
#micBtn {
|
104 |
+
font-size: 20px;
|
105 |
+
display: flex;
|
106 |
+
align-items: center;
|
107 |
+
justify-content: center;
|
108 |
+
}
|
109 |
+
|
110 |
+
p {
|
111 |
+
margin: 8px 0;
|
112 |
+
line-height: 1.5;
|
113 |
+
}
|
114 |
+
</style>
|
115 |
+
</head>
|
116 |
+
<body>
|
117 |
+
<div id="header">
|
118 |
+
<div id="clock">Loading time...</div>
|
119 |
+
</div>
|
120 |
+
<div id="chatbox">
|
121 |
+
<h1>Delta AI Voice & Text Chat</h1>
|
122 |
+
<div id="output"></div>
|
123 |
+
<div class="input-row">
|
124 |
+
<input type="text" id="userInput" placeholder="Ask Delta anything...">
|
125 |
+
<button id="micBtn">🎤</button>
|
126 |
+
<button id="submitBtn">Send</button>
|
127 |
+
</div>
|
128 |
+
</div>
|
129 |
+
|
130 |
+
<script>
|
131 |
+
// Set up the clock
|
132 |
+
function updateClock() {
|
133 |
+
const now = new Date();
|
134 |
+
const hours = String(now.getHours()).padStart(2, '0');
|
135 |
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
136 |
+
const seconds = String(now.getSeconds()).padStart(2, '0');
|
137 |
+
document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}`;
|
138 |
+
}
|
139 |
+
setInterval(updateClock, 1000);
|
140 |
+
updateClock();
|
141 |
+
|
142 |
+
// Typewriter effect
|
143 |
+
function typeWriter(text, element, delay = 20, callback) {
|
144 |
+
let i = 0;
|
145 |
+
function type() {
|
146 |
+
if (i < text.length) {
|
147 |
+
element.innerHTML += text.charAt(i);
|
148 |
+
i++;
|
149 |
+
setTimeout(type, delay);
|
150 |
+
} else if (callback) {
|
151 |
+
callback();
|
152 |
+
}
|
153 |
+
}
|
154 |
+
type();
|
155 |
+
}
|
156 |
+
|
157 |
+
// Function to speak back the AI response
|
158 |
+
function speakText(text) {
|
159 |
+
const speech = new SpeechSynthesisUtterance(text);
|
160 |
+
speech.lang = 'en-US';
|
161 |
+
window.speechSynthesis.speak(speech);
|
162 |
+
}
|
163 |
+
|
164 |
+
// Displaying response with typewriter effect
|
165 |
+
function displayWithTypewriter(role, message) {
|
166 |
+
const output = document.getElementById('output');
|
167 |
+
const p = document.createElement('p');
|
168 |
+
p.innerHTML = `<strong>${role}:</strong> `;
|
169 |
+
output.appendChild(p);
|
170 |
+
typeWriter(message, p, 40, () => {
|
171 |
+
if (role === 'Delta') {
|
172 |
+
speakText(message); // Speak AI response
|
173 |
+
}
|
174 |
+
});
|
175 |
+
output.scrollTop = output.scrollHeight;
|
176 |
+
}
|
177 |
+
|
178 |
+
// Voice recognition (Speech Recognition API)
|
179 |
+
let recognition;
|
180 |
+
if ('webkitSpeechRecognition' in window) {
|
181 |
+
recognition = new webkitSpeechRecognition();
|
182 |
+
recognition.continuous = false; // Stops after one sentence
|
183 |
+
recognition.interimResults = false;
|
184 |
+
recognition.lang = 'en-US';
|
185 |
+
|
186 |
+
recognition.onresult = function(event) {
|
187 |
+
const userInput = event.results[0][0].transcript;
|
188 |
+
document.getElementById('userInput').value = userInput;
|
189 |
+
sendMessage(userInput);
|
190 |
+
};
|
191 |
+
|
192 |
+
recognition.onerror = function(event) {
|
193 |
+
console.error('Speech recognition error', event);
|
194 |
+
};
|
195 |
+
}
|
196 |
+
|
197 |
+
// Send message function
|
198 |
+
async function sendMessage(userInput) {
|
199 |
+
if (!userInput) return;
|
200 |
+
|
201 |
+
displayWithTypewriter("You", userInput);
|
202 |
+
|
203 |
+
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
204 |
+
method: 'POST',
|
205 |
+
headers: {
|
206 |
+
'Authorization': 'Bearer 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',
|
207 |
+
'Content-Type': 'application/json'
|
208 |
+
},
|
209 |
+
body: JSON.stringify({
|
210 |
+
model: "gpt-3.5-turbo",
|
211 |
+
messages: [{ role: "user", content: userInput }],
|
212 |
+
max_tokens: 150
|
213 |
+
})
|
214 |
+
});
|
215 |
+
const data = await response.json();
|
216 |
+
const aiMessage = data.choices[0].message.content;
|
217 |
+
displayWithTypewriter("Delta", aiMessage);
|
218 |
+
}
|
219 |
+
|
220 |
+
// Button to submit text
|
221 |
+
document.getElementById('submitBtn').addEventListener('click', () => {
|
222 |
+
const userInput = document.getElementById('userInput').value;
|
223 |
+
sendMessage(userInput);
|
224 |
+
});
|
225 |
+
|
226 |
+
// Button to start voice recognition
|
227 |
+
document.getElementById('micBtn').addEventListener('click', () => {
|
228 |
+
recognition.start();
|
229 |
+
});
|
230 |
+
</script>
|
231 |
+
</body>
|
232 |
+
</html>
|