Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
23abdce
1
Parent(s):
372483f
debug figure out timeout
Browse files
client.py
CHANGED
@@ -50,7 +50,7 @@ async def send_heartbeat(websocket):
|
|
50 |
except websockets.ConnectionClosed:
|
51 |
print("Connection closed, stopping heartbeat")
|
52 |
break
|
53 |
-
await asyncio.sleep(
|
54 |
|
55 |
|
56 |
async def run_client():
|
@@ -58,12 +58,15 @@ async def run_client():
|
|
58 |
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
59 |
ssl_context.check_hostname = False
|
60 |
ssl_context.verify_mode = ssl.CERT_NONE
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
asyncio.run(run_client())
|
|
|
50 |
except websockets.ConnectionClosed:
|
51 |
print("Connection closed, stopping heartbeat")
|
52 |
break
|
53 |
+
await asyncio.sleep(3) # Send ping every 30 seconds (adjust as needed)
|
54 |
|
55 |
|
56 |
async def run_client():
|
|
|
58 |
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
59 |
ssl_context.check_hostname = False
|
60 |
ssl_context.verify_mode = ssl.CERT_NONE
|
61 |
+
while True:
|
62 |
+
try:
|
63 |
+
async with websockets.connect(uri, ssl=ssl_context, ping_timeout=120,ping_interval=None) as websocket:
|
64 |
+
await asyncio.gather(
|
65 |
+
send_audio(websocket),
|
66 |
+
receive_transcription(websocket),
|
67 |
+
send_heartbeat(websocket)
|
68 |
+
)
|
69 |
+
except websockets.ConnectionClosedError as e:
|
70 |
+
print(f"web closed :{e}")
|
71 |
|
72 |
asyncio.run(run_client())
|
infer.py
CHANGED
@@ -13,7 +13,7 @@ import sys
|
|
13 |
import asyncio
|
14 |
|
15 |
# Configure logging
|
16 |
-
logging.basicConfig(level=logging.
|
17 |
|
18 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
19 |
logging.info(f'Device selected: {device}')
|
@@ -192,19 +192,6 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
192 |
await websocket.accept()
|
193 |
logging.info("WebSocket connection established successfully.")
|
194 |
|
195 |
-
async def send_ping():
|
196 |
-
"""Function to send periodic ping to keep the connection alive."""
|
197 |
-
while True:
|
198 |
-
try:
|
199 |
-
await websocket.ping()
|
200 |
-
logging.info("Sent keepalive ping to client.")
|
201 |
-
await asyncio.sleep(10) # Ping every 10 seconds (adjust the interval as needed)
|
202 |
-
except Exception as e:
|
203 |
-
logging.error(f"Error sending ping: {e}")
|
204 |
-
break
|
205 |
-
|
206 |
-
ping_task = asyncio.create_task(send_ping())
|
207 |
-
|
208 |
try:
|
209 |
processed_segments = [] # Keeps track of the segments already transcribed
|
210 |
accumulated_audio_size = 0 # Track how much audio data has been buffered
|
|
|
13 |
import asyncio
|
14 |
|
15 |
# Configure logging
|
16 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s',handlers=[logging.StreamHandler(sys.stdout)])
|
17 |
|
18 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
19 |
logging.info(f'Device selected: {device}')
|
|
|
192 |
await websocket.accept()
|
193 |
logging.info("WebSocket connection established successfully.")
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
try:
|
196 |
processed_segments = [] # Keeps track of the segments already transcribed
|
197 |
accumulated_audio_size = 0 # Track how much audio data has been buffered
|