File size: 24,456 Bytes
75b2225 | 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CurhatAI - Teman Curhat Berbasis Suara</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/franc@6.0.0/dist/franc.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
}
.waveform {
background: rgba(255, 255, 255, 0.2);
border-radius: 16px;
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
}
.chat-bubble {
max-width: 80%;
padding: 12px 16px;
border-radius: 18px;
position: relative;
margin-bottom: 12px;
animation: fadeIn 0.3s ease-out;
}
.user-bubble {
background-color: #6366f1;
color: white;
align-self: flex-end;
border-bottom-right-radius: 4px;
}
.ai-bubble {
background-color: white;
color: #1f2937;
align-self: flex-start;
border-bottom-left-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.pulse {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% { opacity: 0.6; }
50% { opacity: 1; }
100% { opacity: 0.6; }
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.recording-animation {
animation: recordingPulse 1.5s infinite;
}
@keyframes recordingPulse {
0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
</style>
</head>
<body class="flex flex-col items-center py-8 px-4">
<div class="w-full max-w-2xl">
<!-- Header -->
<header class="flex flex-col items-center mb-8">
<div class="flex items-center mb-4">
<i class="fas fa-headphones text-indigo-500 text-3xl mr-3"></i>
<h1 class="text-3xl font-bold text-gray-800">Curhat<span class="text-indigo-500">AI</span></h1>
</div>
<p class="text-gray-600 text-center max-w-md">
Teman curhat berbasis suara yang selalu siap mendengarkan. Ungkapkan perasaanmu dengan nyaman.
</p>
</header>
<!-- Disclaimer -->
<div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6 rounded">
<div class="flex">
<div class="flex-shrink-0">
<i class="fas fa-exclamation-circle text-yellow-400"></i>
</div>
<div class="ml-3">
<p class="text-sm text-yellow-700">
<strong>Perhatian:</strong> AI ini bukan pengganti profesional kesehatan mental. Jika Anda membutuhkan bantuan serius, silakan hubungi tenaga profesional.
</p>
</div>
</div>
</div>
<!-- Chat Container -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-6">
<!-- Chat Header -->
<div class="bg-indigo-500 px-4 py-3 flex items-center">
<div class="w-3 h-3 rounded-full bg-white mr-2"></div>
<div class="w-3 h-3 rounded-full bg-white/70 mr-2"></div>
<div class="w-3 h-3 rounded-full bg-white/40"></div>
<div class="ml-auto flex items-center">
<span class="text-white font-medium">Teman Curhat AI</span>
<div class="ml-2 w-2 h-2 rounded-full bg-green-300"></div>
</div>
</div>
<!-- Chat Messages -->
<div id="chat-container" class="h-96 overflow-y-auto p-4 flex flex-col bg-gray-50">
<div class="chat-bubble ai-bubble">
<p>Halo! Aku di sini untuk mendengarkan curhatanmu. Klik tombol mikrofon di bawah dan mulai berbicara ya. Aku akan berusaha memahami perasaanmu.</p>
</div>
</div>
<!-- Waveform Visualizer -->
<div id="waveform" class="waveform h-16 mx-4 mb-4 hidden flex items-center justify-center">
<canvas id="visualizer" class="w-full h-full"></canvas>
</div>
<!-- Controls -->
<div class="px-4 py-3 bg-white border-t border-gray-200 flex flex-col items-center">
<div class="flex items-center mb-2">
<button id="record-btn" class="bg-indigo-500 hover:bg-indigo-600 text-white rounded-full w-16 h-16 flex items-center justify-center shadow-lg transition-all duration-300">
<i class="fas fa-microphone text-xl"></i>
</button>
<button id="stop-btn" class="ml-4 bg-red-500 hover:bg-red-600 text-white rounded-full w-12 h-12 flex items-center justify-center shadow-lg transition-all duration-300 hidden">
<i class="fas fa-stop"></i>
</button>
</div>
<p id="status-text" class="text-sm text-gray-500">Tekan tombol mikrofon untuk mulai merekam</p>
<!-- Privacy Controls -->
<div class="mt-4 flex items-center text-sm">
<label class="inline-flex items-center">
<input type="checkbox" id="save-toggle" class="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out">
<span class="ml-2 text-gray-600">Izinkan penyimpanan data suara saya</span>
</label>
<button id="delete-btn" class="ml-4 text-indigo-500 hover:text-indigo-700 text-sm font-medium">
<i class="fas fa-trash-alt mr-1"></i> Hapus Data
</button>
</div>
</div>
</div>
<!-- Feedback Section -->
<div class="bg-white rounded-xl shadow-lg p-4 mb-6">
<h3 class="font-medium text-gray-800 mb-3">Bagaimana pengalaman curhatmu hari ini?</h3>
<div class="flex items-center justify-center space-x-4">
<button class="feedback-btn p-2 rounded-full hover:bg-gray-100" data-rating="good">
<i class="far fa-smile text-2xl text-green-500"></i>
</button>
<button class="feedback-btn p-2 rounded-full hover:bg-gray-100" data-rating="neutral">
<i class="far fa-meh text-2xl text-yellow-500"></i>
</button>
<button class="feedback-btn p-2 rounded-full hover:bg-gray-100" data-rating="bad">
<i class="far fa-frown text-2xl text-red-500"></i>
</button>
</div>
<div id="feedback-form" class="mt-3 hidden">
<textarea id="feedback-text" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" placeholder="Beri tahu kami lebih detail (opsional)"></textarea>
<button id="submit-feedback" class="mt-2 bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-md text-sm font-medium">
Kirim Feedback
</button>
</div>
</div>
<!-- Language Indicator -->
<div class="flex items-center justify-center text-sm text-gray-500">
<i class="fas fa-language mr-2"></i>
<span id="language-indicator">Mendeteksi bahasa secara otomatis</span>
</div>
</div>
<script>
// DOM Elements
const recordBtn = document.getElementById('record-btn');
const stopBtn = document.getElementById('stop-btn');
const chatContainer = document.getElementById('chat-container');
const statusText = document.getElementById('status-text');
const waveform = document.getElementById('waveform');
const visualizer = document.getElementById('visualizer');
const saveToggle = document.getElementById('save-toggle');
const deleteBtn = document.getElementById('delete-btn');
const feedbackBtns = document.querySelectorAll('.feedback-btn');
const feedbackForm = document.getElementById('feedback-form');
const feedbackText = document.getElementById('feedback-text');
const submitFeedback = document.getElementById('submit-feedback');
const languageIndicator = document.getElementById('language-indicator');
// Audio Context and Variables
let audioContext;
let analyser;
let microphone;
let scriptProcessor;
let recording = false;
let audioChunks = [];
let mediaRecorder;
let canvasCtx = visualizer.getContext('2d');
// Initialize Audio Context
function initAudioContext() {
try {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
analyser = audioContext.createAnalyser();
analyser.fftSize = 256;
scriptProcessor = audioContext.createScriptProcessor(2048, 1, 1);
scriptProcessor.connect(audioContext.destination);
analyser.connect(scriptProcessor);
scriptProcessor.onaudioprocess = function() {
if (!recording) return;
const array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(array);
canvasCtx.clearRect(0, 0, visualizer.width, visualizer.height);
const barWidth = (visualizer.width / array.length) * 2.5;
let x = 0;
for (let i = 0; i < array.length; i++) {
const barHeight = (array[i] / 255) * visualizer.height;
canvasCtx.fillStyle = `rgb(${Math.floor(barHeight * 2)}, 100, 255)`;
canvasCtx.fillRect(x, visualizer.height - barHeight, barWidth, barHeight);
x += barWidth + 1;
}
};
return true;
} catch (e) {
console.error('Error initializing audio context:', e);
return false;
}
}
// Start Recording
async function startRecording() {
try {
if (!audioContext) {
if (!initAudioContext()) {
throw new Error('Audio context initialization failed');
}
}
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
microphone = audioContext.createMediaStreamSource(stream);
microphone.connect(analyser);
audioChunks = [];
mediaRecorder.ondataavailable = (event) => {
if (event.data.size > 0) {
audioChunks.push(event.data);
}
};
mediaRecorder.onstop = async () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
processRecording(audioBlob);
};
mediaRecorder.start(100); // Collect data every 100ms
recording = true;
recordBtn.classList.add('hidden');
stopBtn.classList.remove('hidden');
waveform.classList.remove('hidden');
statusText.textContent = "Sedang merekam...";
recordBtn.classList.remove('recording-animation');
recordBtn.classList.add('recording-animation');
} catch (error) {
console.error('Error starting recording:', error);
statusText.textContent = "Error: " + error.message;
addAIMessage("Maaf, aku tidak bisa mengakses mikrofonmu. Pastikan kamu sudah memberikan izin akses mikrofon.");
}
}
// Stop Recording
function stopRecording() {
if (mediaRecorder && recording) {
mediaRecorder.stop();
recording = false;
// Stop all tracks
mediaRecorder.stream.getTracks().forEach(track => track.stop());
recordBtn.classList.remove('hidden');
stopBtn.classList.add('hidden');
waveform.classList.add('hidden');
statusText.textContent = "Memproses curhatanmu...";
recordBtn.classList.remove('recording-animation');
}
}
// Process Recording
async function processRecording(audioBlob) {
try {
// In a real implementation, you would send this to Whisper API
// For demo purposes, we'll simulate the transcription
// Simulate API call delay
statusText.textContent = "Mentranskrip suara...";
// Mock transcription (in real app, use Whisper API)
const mockResponses = {
'id': "Aku merasa sangat sedih hari ini karena pekerjaanku menumpuk dan atasan tidak menghargai usahaku.",
'en': "I'm feeling really sad today because my work is piling up and my boss doesn't appreciate my efforts."
};
// Simulate language detection
setTimeout(() => {
const detectedLang = Math.random() > 0.5 ? 'id' : 'en';
const transcribedText = mockResponses[detectedLang];
// Update UI with user message
addUserMessage(transcribedText);
// Show detected language
const langNames = { 'id': 'Bahasa Indonesia', 'en': 'English' };
languageIndicator.textContent = `Terdeteksi: ${langNames[detectedLang]}`;
// Get AI response
getAIResponse(transcribedText, detectedLang);
}, 1500);
} catch (error) {
console.error('Error processing recording:', error);
statusText.textContent = "Error memproses rekaman";
addAIMessage("Maaf, ada masalah saat memproses curhatanmu. Coba lagi ya.");
}
}
// Get AI Response (Mock for demo)
function getAIResponse(text, lang) {
statusText.textContent = "Teman curhat sedang memikirkan respon...";
// Mock AI responses based on language
const aiResponses = {
'id': [
"Aduh, aku turut sedih mendengar itu. Pekerjaan yang menumpuk memang bisa bikin stres ya. Tapi ingat, kamu sudah melakukan yang terbaik!",
"Wah, aku bisa mengerti perasaanmu. Tidak dihargai itu memang menyakitkan. Mungkin kamu bisa coba bicara baik-baik dengan atasanmu tentang perasaan ini?",
"Sedih banget dengar ceritamu. Jangan lupa untuk istirahat yang cukup ya, jangan terlalu keras sama dirimu sendiri."
],
'en': [
"Oh no, I'm really sorry to hear that. A pile of work can be really stressful. But remember, you're doing your best!",
"I can understand how you feel. Not being appreciated does hurt. Maybe you could try talking to your boss about how you feel?",
"That's really sad to hear. Don't forget to get enough rest, don't be too hard on yourself."
]
};
// Simulate API call delay
setTimeout(() => {
const responses = aiResponses[lang];
const randomResponse = responses[Math.floor(Math.random() * responses.length)];
addAIMessage(randomResponse);
statusText.textContent = "Tekan tombol mikrofon untuk curhat lagi";
// Enable TTS button
const lastAIMessage = chatContainer.lastElementChild;
const ttsBtn = document.createElement('button');
ttsBtn.className = 'mt-2 text-indigo-500 hover:text-indigo-700 text-sm flex items-center';
ttsBtn.innerHTML = '<i class="fas fa-volume-up mr-1"></i> Dengarkan';
ttsBtn.onclick = () => speakText(randomResponse, lang);
lastAIMessage.appendChild(document.createElement('div')).appendChild(ttsBtn);
}, 2000);
}
// Text-to-Speech
function speakText(text, lang) {
if ('speechSynthesis' in window) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = lang === 'id' ? 'id-ID' : 'en-US';
utterance.rate = 0.9;
utterance.pitch = 1;
// Find a female voice if available
const voices = speechSynthesis.getVoices();
const preferredVoices = voices.filter(voice =>
(lang === 'id' && voice.lang === 'id-ID') ||
(lang === 'en' && voice.lang.startsWith('en-'))
);
if (preferredVoices.length > 0) {
utterance.voice = preferredVoices.find(v => v.name.includes('Female')) || preferredVoices[0];
}
speechSynthesis.speak(utterance);
} else {
addAIMessage("Maaf, browser kamu tidak mendukung fitur text-to-speech.");
}
}
// Add User Message to Chat
function addUserMessage(text) {
const messageDiv = document.createElement('div');
messageDiv.className = 'chat-bubble user-bubble';
messageDiv.innerHTML = `<p>${text}</p>`;
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
// Add AI Message to Chat
function addAIMessage(text) {
const messageDiv = document.createElement('div');
messageDiv.className = 'chat-bubble ai-bubble';
// Add typing indicator first
messageDiv.innerHTML = `
<div class="flex items-center">
<div class="w-6 h-6 rounded-full bg-indigo-100 flex items-center justify-center mr-2">
<i class="fas fa-robot text-indigo-500"></i>
</div>
<div class="typing-indicator flex space-x-1">
<div class="w-2 h-2 bg-gray-400 rounded-full pulse"></div>
<div class="w-2 h-2 bg-gray-400 rounded-full pulse" style="animation-delay: 0.2s"></div>
<div class="w-2 h-2 bg-gray-400 rounded-full pulse" style="animation-delay: 0.4s"></div>
</div>
</div>
`;
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
// Replace with actual message after a delay
setTimeout(() => {
messageDiv.innerHTML = `
<div class="flex items-center mb-2">
<div class="w-6 h-6 rounded-full bg-indigo-100 flex items-center justify-center mr-2">
<i class="fas fa-robot text-indigo-500"></i>
</div>
<span class="font-medium text-gray-700">Teman Curhat AI</span>
</div>
<p>${text}</p>
`;
chatContainer.scrollTop = chatContainer.scrollHeight;
}, 1000);
}
// Event Listeners
recordBtn.addEventListener('click', startRecording);
stopBtn.addEventListener('click', stopRecording);
// Feedback System
feedbackBtns.forEach(btn => {
btn.addEventListener('click', () => {
feedbackBtns.forEach(b => b.classList.remove('bg-gray-100'));
btn.classList.add('bg-gray-100');
feedbackForm.classList.remove('hidden');
});
});
submitFeedback.addEventListener('click', () => {
const rating = document.querySelector('.feedback-btn.bg-gray-100')?.dataset.rating;
const comment = feedbackText.value;
// In a real app, send this to your backend
console.log('Feedback submitted:', { rating, comment });
// Show thank you message
addAIMessage("Terima kasih atas feedbackmu! Aku akan terus berusaha menjadi lebih baik.");
// Reset feedback form
feedbackBtns.forEach(b => b.classList.remove('bg-gray-100'));
feedbackForm.classList.add('hidden');
feedbackText.value = '';
});
// Delete Data
deleteBtn.addEventListener('click', () => {
// In a real app, this would delete stored data
alert("Data suara dan percakapan kamu telah dihapus.");
});
// Initialize
document.addEventListener('DOMContentLoaded', () => {
// Load speech synthesis voices
if ('speechSynthesis' in window) {
speechSynthesis.onvoiceschanged = () => {
console.log('Voices loaded');
};
// Chrome needs this
if (speechSynthesis.getVoices().length === 0) {
speechSynthesis.addEventListener('voiceschanged', () => {
console.log('Voices loaded after event');
});
}
}
// Set canvas size
visualizer.width = waveform.clientWidth;
visualizer.height = waveform.clientHeight;
});
// Handle window resize
window.addEventListener('resize', () => {
visualizer.width = waveform.clientWidth;
visualizer.height = waveform.clientHeight;
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=MEIUT/voicecht" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |