AshDavid12 commited on
Commit
23abdce
·
1 Parent(s): 372483f

debug figure out timeout

Browse files
Files changed (2) hide show
  1. client.py +11 -8
  2. infer.py +1 -14
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(600) # Send ping every 30 seconds (adjust as needed)
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
- async with websockets.connect(uri, ssl=ssl_context, ping_timeout=120,ping_interval=10) as websocket:
63
- await asyncio.gather(
64
- send_audio(websocket),
65
- receive_transcription(websocket),
66
- send_heartbeat(websocket)
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.INFO, 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,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