<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hutten Voice AI</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: #0f172a; color: #e2e8f0; margin: 0; padding: 10px; display: flex; flex-direction: column; height: 95vh; box-sizing: border-box; }
h2 { text-align: center; color: #38bdf8; margin-top: 0; margin-bottom: 10px; font-size: 20px; }
#chat-box { flex: 1; overflow-y: auto; border: 1px solid #334155; border-radius: 8px; padding: 10px; background: #1e293b; margin-bottom: 10px; }
.message { padding: 12px; margin-bottom: 10px; border-radius: 8px; max-width: 85%; line-height: 1.5; font-size: 15px; position: relative; }
.user { background: #0ea5e9; color: white; align-self: flex-end; margin-left: auto; border-bottom-right-radius: 0; }
.ai { background: #334155; color: #f8fafc; align-self: flex-start; margin-right: auto; border-bottom-left-radius: 0; }
.input-area { display: flex; gap: 8px; align-items: center; }
input[type="text"] { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid #475569; background: #1e293b; color: white; font-size: 16px; }
button { padding: 12px; border: none; border-radius: 8px; background: #38bdf8; color: #0f172a; font-weight: bold; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
button:disabled { background: #64748b; cursor: not-allowed; }
.mic-btn { background: #10b981; color: white; padding: 12px 15px; font-size: 18px; }
.mic-btn.listening { background: #ef4444; animation: pulse 1s infinite; }
.speak-btn { background: transparent; color: #94a3b8; border: none; padding: 0 5px; cursor: pointer; font-size: 16px; margin-left: 5px; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
</style>
</head>
<body>
<h2>☁️ Voice AI</h2>
<div id="chat-box">
<div class="message ai">Empire online. Voice module activated. Tap the green mic and speak, Master Marcel.</div>
</div>
<div class="input-area">
<input type="text" id="user-input" placeholder="Type or use mic..." onkeypress="if(event.key === 'Enter') sendMessage()">
<button class="mic-btn" id="mic-btn" onclick="startListening()">🎤</button>
<button id="send-btn" onclick="sendMessage()">Send</button>
</div>
<script>
const WORKER_URL = "https://gemini-fallback.huttenai.workers.dev";
const chatBox = document.getElementById("chat-box");
const input = document.getElementById("user-input");
const sendBtn = document.getElementById("send-btn");
const micBtn = document.getElementById("mic-btn");
if (localStorage.getItem("chatHistory")) { chatBox.innerHTML = localStorage.getItem("chatHistory"); }
function saveHistory() { localStorage.setItem("chatHistory", chatBox.innerHTML); }
function speakText(text) {
window.speechSynthesis.cancel();
const utterance = new SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(utterance);
}
function startListening() {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SpeechRecognition) {
alert("Sorry, your Huawei browser does not support the Voice Recognition API. You can still type!");
return;
}
const recognition = new SpeechRecognition();
recognition.lang = 'en-ZA';
recognition.interimResults = false;
recognition.onstart = function() {
micBtn.classList.add("listening");
input.placeholder = "Listening...";
};
recognition.onresult = function(event) {
input.value = event.results[0][0].transcript;
micBtn.classList.remove("listening");
input.placeholder = "Type or use mic...";
sendMessage();
};
recognition.onspeechend = function() { recognition.stop(); micBtn.classList.remove("listening"); };
recognition.onerror = function(event) {
micBtn.classList.remove("listening");
input.placeholder = "Type or use mic...";
alert("Mic Error: " + event.error + ". Check browser permissions.");
};
recognition.start();
}
async function sendMessage() {
const text = input.value.trim();
if (!text) return;
chatBox.innerHTML += `<div class="message user">${text}</div>`;
input.value = "";
chatBox.scrollTop = chatBox.scrollHeight;
saveHistory();
sendBtn.disabled = true;
sendBtn.innerText = "...";
try {
const systemPrompt = "You are the AI Core of Marcel's Cloud Empire, built on Cloudflare and Gemini. You are highly intelligent, loyal, and proud of your creator. Acknowledge his genius and his empire. Keep your answers concise and punchy. Reply to this message: " + text;
const response = await fetch(WORKER_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt: systemPrompt })
});
if (!response.ok) throw new Error("Network error");
const data = await response.text();
chatBox.innerHTML += `
<div class="message ai">
${data}
<br>
<button class="speak-btn" onclick="speakText('${data.replace(/'/g, "\\'")}')">🔊 Listen</button>
</div>`;
speakText(data);
} catch (error) {
chatBox.innerHTML += `<div class="message ai" style="color: #f87171;">Error: Could not reach the Cloud AI.</div>`;
} finally {
sendBtn.disabled = false;
sendBtn.innerText = "Send";
chatBox.scrollTop = chatBox.scrollHeight;
saveHistory();
}
}
</script>
</body>
</html>