Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,14 +28,14 @@ async def home():
|
|
| 28 |
|
| 29 |
async function start() {
|
| 30 |
|
| 31 |
-
// HuggingFace
|
| 32 |
-
const wsUrl = "wss://
|
| 33 |
-
console.log("Connecting
|
| 34 |
|
| 35 |
ws = new WebSocket(wsUrl);
|
| 36 |
|
| 37 |
ws.onopen = () => {
|
| 38 |
-
console.log("WebSocket connected
|
| 39 |
document.getElementById("status").innerText = "Connected. Listening…";
|
| 40 |
};
|
| 41 |
|
|
@@ -50,8 +50,7 @@ async def home():
|
|
| 50 |
};
|
| 51 |
|
| 52 |
ws.onmessage = (event) => {
|
| 53 |
-
console.log("
|
| 54 |
-
|
| 55 |
const audio = new Audio("data:audio/wav;base64," + event.data);
|
| 56 |
audio.play();
|
| 57 |
};
|
|
@@ -62,10 +61,10 @@ async def home():
|
|
| 62 |
rec = new MediaRecorder(stream, { mimeType: "audio/webm" });
|
| 63 |
|
| 64 |
rec.ondataavailable = async (e) => {
|
| 65 |
-
ws.send(await e.data.arrayBuffer()); // send audio to backend
|
| 66 |
};
|
| 67 |
|
| 68 |
-
rec.start(300); // send
|
| 69 |
document.getElementById("status").innerText = "Listening…";
|
| 70 |
}
|
| 71 |
|
|
|
|
| 28 |
|
| 29 |
async function start() {
|
| 30 |
|
| 31 |
+
// IMPORTANT: HuggingFace requires absolute WebSocket domain
|
| 32 |
+
const wsUrl = "wss://sanjaystarc-voice-agent.hf.space/ws";
|
| 33 |
+
console.log("Connecting WebSocket:", wsUrl);
|
| 34 |
|
| 35 |
ws = new WebSocket(wsUrl);
|
| 36 |
|
| 37 |
ws.onopen = () => {
|
| 38 |
+
console.log("WebSocket connected.");
|
| 39 |
document.getElementById("status").innerText = "Connected. Listening…";
|
| 40 |
};
|
| 41 |
|
|
|
|
| 50 |
};
|
| 51 |
|
| 52 |
ws.onmessage = (event) => {
|
| 53 |
+
console.log("Audio reply received.");
|
|
|
|
| 54 |
const audio = new Audio("data:audio/wav;base64," + event.data);
|
| 55 |
audio.play();
|
| 56 |
};
|
|
|
|
| 61 |
rec = new MediaRecorder(stream, { mimeType: "audio/webm" });
|
| 62 |
|
| 63 |
rec.ondataavailable = async (e) => {
|
| 64 |
+
ws.send(await e.data.arrayBuffer()); // send raw audio to backend
|
| 65 |
};
|
| 66 |
|
| 67 |
+
rec.start(300); // send chunks every 300 ms
|
| 68 |
document.getElementById("status").innerText = "Listening…";
|
| 69 |
}
|
| 70 |
|