-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprof.html
56 lines (52 loc) · 2.01 KB
/
prof.html
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
<!DOCTYPE html>
<html>
<head>
<title>Audio Chat (Prof side)</title>
</head>
<style>
#recording-indicator {
display: none;
color: red;
font-weight: bold;
margin-top: 10px;
}
</style>
<body>
<h1>WebSocket Audio Chat (Prof Side)</h1>
<h2 id = "speaker-status">Current speaker: </h2>
<button> for gesture</button>
<script>
// var ws = new WebSocket(`ws://localhost:8000/ws/${client_id}`);
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
function playAudioBuffer(audioBuffer) {
const source = audioContext.createBufferSource();
source.buffer = audioBuffer;
source.connect(audioContext.destination);
source.start(0);
}
var ws = new WebSocket(`ws://localhost:8000/ws/prof`);
ws.binaryType = 'arraybuffer'; // To handle binary audio data
ws.onmessage = async (event) => {
if (event.data instanceof ArrayBuffer) {
// Decode and play the audio data
console.log("Audio chunk received:", event.data);
if (event.data.byteLength > 0) {
try {
const audioBuffer = await audioContext.decodeAudioData(event.data);
if (audioBuffer){
playAudioBuffer(audioBuffer);
}
} catch (error) {
console.log(error)
}
}
} else {
const message = JSON.parse(event.data);
if (message.action === "stop") {
console.log("Stop signal received, stopping audio playback");
}
}
}
</script>
</body>
</html>