Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +40 -40
templates/index.html
CHANGED
|
@@ -1,70 +1,70 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html lang="
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>Voice Agent</title>
|
| 6 |
<script src="https://cdn.jsdelivr.net/npm/livekit-client/dist/livekit-client.umd.min.js"></script>
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
</style>
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<div class="card">
|
| 15 |
-
<h1>
|
| 16 |
-
<button id="
|
| 17 |
-
<
|
| 18 |
-
<
|
| 19 |
<div id="transcript">Belum ada percakapan...</div>
|
| 20 |
</div>
|
| 21 |
|
| 22 |
<script>
|
| 23 |
-
const
|
| 24 |
-
const
|
| 25 |
-
const
|
| 26 |
-
const
|
| 27 |
let room;
|
| 28 |
|
| 29 |
-
|
| 30 |
try {
|
|
|
|
| 31 |
const res = await fetch('/token');
|
| 32 |
const data = await res.json();
|
| 33 |
|
| 34 |
-
room = new LivekitClient.Room(
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
// 1. Event saat ada data (transkrip) masuk
|
| 40 |
-
room.on(LivekitClient.RoomEvent.DataReceived, (payload, participant) => {
|
| 41 |
const text = new TextDecoder().decode(payload);
|
| 42 |
-
|
| 43 |
-
transcriptDiv.scrollTop = transcriptDiv.scrollHeight;
|
| 44 |
});
|
| 45 |
|
| 46 |
await room.connect(data.server_url, data.token);
|
| 47 |
-
statusDiv.innerText = "Status: Terhubung";
|
| 48 |
await room.localParticipant.setMicrophoneEnabled(true);
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
const trackPub = room.localParticipant.audioTrackPublications.values().next().value;
|
| 54 |
-
if (trackPub && trackPub.track) {
|
| 55 |
-
const level = trackPub.track.getVolumeLevel() * 100;
|
| 56 |
-
volumeBar.style.width = Math.min(level * 2, 100) + "%";
|
| 57 |
-
}
|
| 58 |
-
}
|
| 59 |
-
}, 100);
|
| 60 |
-
|
| 61 |
} catch (e) {
|
| 62 |
-
|
| 63 |
-
statusDiv.innerText = "Gagal: " + e.message;
|
| 64 |
}
|
| 65 |
-
}
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
</script>
|
| 69 |
</body>
|
| 70 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html lang="id">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
|
|
|
| 5 |
<script src="https://cdn.jsdelivr.net/npm/livekit-client/dist/livekit-client.umd.min.js"></script>
|
| 6 |
<style>
|
| 7 |
+
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f7f6; display: flex; justify-content: center; padding-top: 50px; }
|
| 8 |
+
.card { background: white; padding: 30px; border-radius: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); width: 350px; text-align: center; }
|
| 9 |
+
h1 { color: #333; font-size: 24px; margin-bottom: 20px; }
|
| 10 |
+
button { padding: 12px 24px; font-size: 16px; border: none; border-radius: 10px; cursor: pointer; transition: 0.3s; margin: 5px; }
|
| 11 |
+
#btn-hubungkan { background: #007bff; color: white; }
|
| 12 |
+
#btn-batal { background: #dc3545; color: white; }
|
| 13 |
+
button:disabled { background: #ccc; cursor: not-allowed; }
|
| 14 |
+
#status { margin: 15px 0; font-weight: bold; color: #555; }
|
| 15 |
+
#transcript { margin-top: 20px; padding: 15px; background: #f8f9fa; border-left: 4px solid #007bff; border-radius: 5px; min-height: 80px; text-align: left; font-size: 14px; color: #444; }
|
| 16 |
</style>
|
| 17 |
</head>
|
| 18 |
<body>
|
| 19 |
<div class="card">
|
| 20 |
+
<h1>Voice Agent</h1>
|
| 21 |
+
<button id="btn-hubungkan">Hubungkan</button>
|
| 22 |
+
<button id="btn-batal" disabled>Batal</button>
|
| 23 |
+
<p id="status">Status: Terputus</p>
|
| 24 |
<div id="transcript">Belum ada percakapan...</div>
|
| 25 |
</div>
|
| 26 |
|
| 27 |
<script>
|
| 28 |
+
const btnHubungkan = document.getElementById('btn-hubungkan');
|
| 29 |
+
const btnBatal = document.getElementById('btn-batal');
|
| 30 |
+
const status = document.getElementById('status');
|
| 31 |
+
const transcript = document.getElementById('transcript');
|
| 32 |
let room;
|
| 33 |
|
| 34 |
+
btnHubungkan.onclick = async () => {
|
| 35 |
try {
|
| 36 |
+
status.innerText = "Menghubungkan...";
|
| 37 |
const res = await fetch('/token');
|
| 38 |
const data = await res.json();
|
| 39 |
|
| 40 |
+
room = new LivekitClient.Room();
|
| 41 |
+
|
| 42 |
+
// Menerima teks dari Agen
|
| 43 |
+
room.on('dataReceived', (payload) => {
|
|
|
|
|
|
|
|
|
|
| 44 |
const text = new TextDecoder().decode(payload);
|
| 45 |
+
transcript.innerHTML = `<b>Agen:</b> ${text}`;
|
|
|
|
| 46 |
});
|
| 47 |
|
| 48 |
await room.connect(data.server_url, data.token);
|
|
|
|
| 49 |
await room.localParticipant.setMicrophoneEnabled(true);
|
| 50 |
+
|
| 51 |
+
status.innerText = "Status: Terhubung";
|
| 52 |
+
btnHubungkan.disabled = true;
|
| 53 |
+
btnBatal.disabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
} catch (e) {
|
| 55 |
+
status.innerText = "Error: " + e.message;
|
|
|
|
| 56 |
}
|
| 57 |
+
};
|
| 58 |
|
| 59 |
+
btnBatal.onclick = () => {
|
| 60 |
+
if (room) {
|
| 61 |
+
room.disconnect();
|
| 62 |
+
status.innerText = "Status: Terputus";
|
| 63 |
+
btnHubungkan.disabled = false;
|
| 64 |
+
btnBatal.disabled = true;
|
| 65 |
+
transcript.innerHTML = "Belum ada percakapan...";
|
| 66 |
+
}
|
| 67 |
+
};
|
| 68 |
</script>
|
| 69 |
</body>
|
| 70 |
</html>
|