Spaces:
Sleeping
Sleeping
Commit
·
ffa6f25
1
Parent(s):
d3215d5
audio_processor
Browse files- shared.py +1 -1
- test_websocket.py +20 -75
shared.py
CHANGED
@@ -578,7 +578,7 @@ class RealtimeSpeakerDiarization:
|
|
578 |
speaker_id = self.speaker_detector.current_speaker
|
579 |
similarity = 1.0
|
580 |
|
581 |
-
if len(self.audio_processor.audio_buffer) % (SAMPLE_RATE // 2)
|
582 |
embedding = self.audio_processor.extract_embedding_from_buffer()
|
583 |
if embedding is not None:
|
584 |
speaker_id, similarity = self.speaker_detector.add_embedding(embedding)
|
|
|
578 |
speaker_id = self.speaker_detector.current_speaker
|
579 |
similarity = 1.0
|
580 |
|
581 |
+
if len(self.audio_processor.audio_buffer) >= SAMPLE_RATE and (len(self.audio_processor.audio_buffer) - SAMPLE_RATE) % (SAMPLE_RATE // 2)==0:
|
582 |
embedding = self.audio_processor.extract_embedding_from_buffer()
|
583 |
if embedding is not None:
|
584 |
speaker_id, similarity = self.speaker_detector.add_embedding(embedding)
|
test_websocket.py
CHANGED
@@ -1,81 +1,26 @@
|
|
|
|
1 |
import asyncio
|
2 |
import websockets
|
3 |
import json
|
4 |
-
import numpy as np
|
5 |
-
import time
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
async with websockets.connect(WS_INFERENCE_ENDPOINT, ping_interval=30) as ws:
|
20 |
-
print("Connected to HF Space inference WebSocket!")
|
21 |
-
|
22 |
-
# Send test data (simulated audio)
|
23 |
-
test_audio = np.zeros(1600, dtype=np.float32).tobytes()
|
24 |
-
await ws.send(test_audio)
|
25 |
-
print(f"Sent test audio data: {len(test_audio)} bytes")
|
26 |
-
|
27 |
-
# Wait for response
|
28 |
-
for _ in range(5): # Try to get 5 responses
|
29 |
-
try:
|
30 |
-
response = await asyncio.wait_for(ws.recv(), timeout=3.0)
|
31 |
-
if isinstance(response, str):
|
32 |
-
try:
|
33 |
-
json_data = json.loads(response)
|
34 |
-
print(f"Received JSON response: {json.dumps(json_data, indent=2)}")
|
35 |
-
except json.JSONDecodeError:
|
36 |
-
print(f"Received non-JSON response: {response[:500]}...")
|
37 |
-
else:
|
38 |
-
print(f"Received binary data: {len(response)} bytes")
|
39 |
-
except asyncio.TimeoutError:
|
40 |
-
print("No response received within timeout")
|
41 |
-
break
|
42 |
-
|
43 |
-
except Exception as e:
|
44 |
-
print(f"Error connecting to HF Space WebSocket: {e}")
|
45 |
-
|
46 |
-
# Test Render Signal WebSocket relay connection
|
47 |
-
print(f"\nConnecting to {WS_RELAY_ENDPOINT}...")
|
48 |
-
try:
|
49 |
-
async with websockets.connect(WS_RELAY_ENDPOINT) as ws:
|
50 |
-
print("Connected to Render Signal WebSocket relay!")
|
51 |
-
|
52 |
-
# Send test configuration message
|
53 |
-
test_config = {
|
54 |
-
"type": "config",
|
55 |
-
"client_id": f"test_client_{time.time()}",
|
56 |
-
"test": True
|
57 |
-
}
|
58 |
-
await ws.send(json.dumps(test_config))
|
59 |
-
print(f"Sent test config: {test_config}")
|
60 |
-
|
61 |
-
# Wait for responses
|
62 |
-
for _ in range(5): # Try to get 5 responses
|
63 |
-
try:
|
64 |
-
response = await asyncio.wait_for(ws.recv(), timeout=3.0)
|
65 |
-
if isinstance(response, str):
|
66 |
-
try:
|
67 |
-
json_data = json.loads(response)
|
68 |
-
print(f"Received JSON response: {json.dumps(json_data, indent=2)}")
|
69 |
-
except json.JSONDecodeError:
|
70 |
-
print(f"Received non-JSON response: {response[:500]}...")
|
71 |
-
else:
|
72 |
-
print(f"Received binary data: {len(response)} bytes")
|
73 |
-
except asyncio.TimeoutError:
|
74 |
-
print("No response received within timeout")
|
75 |
-
break
|
76 |
-
except Exception as e:
|
77 |
-
print(f"Error connecting to Render Signal WebSocket: {e}")
|
78 |
|
79 |
-
|
80 |
-
if __name__ == "__main__":
|
81 |
-
asyncio.run(test_websocket_connections())
|
|
|
1 |
+
import numpy as np
|
2 |
import asyncio
|
3 |
import websockets
|
4 |
import json
|
|
|
|
|
5 |
|
6 |
+
async def test_ws():
|
7 |
+
uri = "wss://androidguy-speaker-diarization.hf.space/ws_inference"
|
8 |
+
async with websockets.connect(uri) as websocket:
|
9 |
+
print("Connected")
|
10 |
+
|
11 |
+
print(await websocket.recv()) # connection_established
|
12 |
+
|
13 |
+
for i in range(20):
|
14 |
+
# Generate random "noise" audio instead of silence
|
15 |
+
audio = (np.random.randn(3200) * 3000).astype(np.int16)
|
16 |
+
await websocket.send(audio.tobytes())
|
17 |
+
print(f"Sent audio chunk {i+1}/20")
|
18 |
|
19 |
+
try:
|
20 |
+
while True:
|
21 |
+
res = await asyncio.wait_for(websocket.recv(), timeout=10)
|
22 |
+
print("Received:", json.dumps(json.loads(res), indent=2))
|
23 |
+
except asyncio.TimeoutError:
|
24 |
+
print("[ERROR] No more responses (timeout)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
asyncio.run(test_ws())
|
|
|
|