Update app.py
Browse files
app.py
CHANGED
|
@@ -713,8 +713,11 @@ async def browser_stream_endpoint(ws: WebSocket):
|
|
| 713 |
while True:
|
| 714 |
# Get audio from the robot queue (non-blocking check)
|
| 715 |
if not state.audio_queue.empty():
|
| 716 |
-
|
| 717 |
-
|
|
|
|
|
|
|
|
|
|
| 718 |
try:
|
| 719 |
# Send as binary message
|
| 720 |
await ws.send_bytes(chunk_bytes)
|
|
@@ -1387,7 +1390,11 @@ APP_JS = """
|
|
| 1387 |
|
| 1388 |
const now = ctx.currentTime;
|
| 1389 |
if (nextTime < now) nextTime = now;
|
| 1390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1391 |
nextTime += floatBuffer.duration;
|
| 1392 |
};
|
| 1393 |
|
|
|
|
| 713 |
while True:
|
| 714 |
# Get audio from the robot queue (non-blocking check)
|
| 715 |
if not state.audio_queue.empty():
|
| 716 |
+
_, chunk_bytes, robot_timestamp = state.audio_queue.get(timeout=0.5)
|
| 717 |
+
|
| 718 |
+
# Track latency if we have a timestamp
|
| 719 |
+
if robot_timestamp is not None:
|
| 720 |
+
state.track_audio_latency(robot_timestamp)
|
| 721 |
try:
|
| 722 |
# Send as binary message
|
| 723 |
await ws.send_bytes(chunk_bytes)
|
|
|
|
| 1390 |
|
| 1391 |
const now = ctx.currentTime;
|
| 1392 |
if (nextTime < now) nextTime = now;
|
| 1393 |
+
|
| 1394 |
+
if (nextTime > now + 0.15) {
|
| 1395 |
+
console.log("Catching up audio latency...");
|
| 1396 |
+
nextTime = now;
|
| 1397 |
+
} src.start(nextTime);
|
| 1398 |
nextTime += floatBuffer.duration;
|
| 1399 |
};
|
| 1400 |
|