AshDavid12 commited on
Commit
cf31b20
·
1 Parent(s): ebaaf9b

close exec change

Browse files
Files changed (2) hide show
  1. client.py +9 -2
  2. infer.py +4 -5
client.py CHANGED
@@ -7,6 +7,7 @@ SAMPLE_RATE = 16000
7
  CHUNK_SIZE = 1024 # Size of the audio chunk sent at a time
8
  AUDIO_FILE = "https://raw.githubusercontent.com/AshDavid12/hugging_face_ivrit_streaming/main/test_copy.mp3" # Path to the mp3 file
9
 
 
10
  async def send_audio(websocket):
11
  with wave.open(AUDIO_FILE, "rb") as wf:
12
  data = wf.readframes(CHUNK_SIZE)
@@ -15,6 +16,7 @@ async def send_audio(websocket):
15
  await asyncio.sleep(CHUNK_SIZE / SAMPLE_RATE) # Simulate real-time by waiting for the duration of the chunk
16
  data = wf.readframes(CHUNK_SIZE)
17
 
 
18
  async def receive_transcription(websocket):
19
  while True:
20
  try:
@@ -24,9 +26,14 @@ async def receive_transcription(websocket):
24
  print(f"Error: {e}")
25
  break
26
 
 
27
  async def run_client():
28
- uri = "wss://gigaverse-ivrit-ai-streaming.hf.space/ws/transcribe" # Replace with your Hugging Face Space WebSocket URL
29
- async with websockets.connect(uri) as websocket:
 
 
 
 
30
  await asyncio.gather(
31
  send_audio(websocket),
32
  receive_transcription(websocket)
 
7
  CHUNK_SIZE = 1024 # Size of the audio chunk sent at a time
8
  AUDIO_FILE = "https://raw.githubusercontent.com/AshDavid12/hugging_face_ivrit_streaming/main/test_copy.mp3" # Path to the mp3 file
9
 
10
+
11
  async def send_audio(websocket):
12
  with wave.open(AUDIO_FILE, "rb") as wf:
13
  data = wf.readframes(CHUNK_SIZE)
 
16
  await asyncio.sleep(CHUNK_SIZE / SAMPLE_RATE) # Simulate real-time by waiting for the duration of the chunk
17
  data = wf.readframes(CHUNK_SIZE)
18
 
19
+
20
  async def receive_transcription(websocket):
21
  while True:
22
  try:
 
26
  print(f"Error: {e}")
27
  break
28
 
29
+ import ssl
30
  async def run_client():
31
+ uri = ("wss://gigaverse-ivrit-ai-streaming.hf.space/ws/transcribe") # Replace with your Hugging Face Space WebSocket URL
32
+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
33
+ ssl_context.check_hostname = False
34
+ ssl_context.verify_mode = ssl.CERT_NONE
35
+
36
+ async with websockets.connect(uri, ssl=ssl_context) as websocket:
37
  await asyncio.gather(
38
  send_audio(websocket),
39
  receive_transcription(websocket)
infer.py CHANGED
@@ -12,7 +12,7 @@ from typing import Optional
12
  import asyncio
13
 
14
  # Configure logging
15
- logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
16
 
17
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
18
  logging.info(f'Device selected: {device}')
@@ -159,11 +159,11 @@ def transcribe_core_ws(audio_file, last_transcribed_time):
159
 
160
  # Track the new segments and update the last transcribed time
161
  for s in segs:
162
- logging.debug(f"Processing segment with start time: {s.start} and end time: {s.end}")
163
 
164
  # Only process segments that start after the last transcribed time
165
  if s.start >= last_transcribed_time:
166
- logging.debug(f"New segment found starting at {s.start} seconds.")
167
  words = [{'start': w.start, 'end': w.end, 'word': w.word, 'probability': w.probability} for w in s.words]
168
 
169
  seg = {
@@ -203,7 +203,7 @@ async def websocket_transcribe(websocket: WebSocket):
203
  # Continuously receive and process audio chunks
204
  while True:
205
  try:
206
- logging.debug("Waiting to receive the next chunk of audio data from WebSocket.")
207
 
208
  # Receive the next chunk of audio data
209
  audio_chunk = await websocket.receive_bytes()
@@ -243,7 +243,6 @@ async def websocket_transcribe(websocket: WebSocket):
243
  await websocket.send_json({"error": str(e)})
244
  finally:
245
  logging.info("Cleaning up and closing WebSocket connection.")
246
- await websocket.close()
247
 
248
 
249
 
 
12
  import asyncio
13
 
14
  # Configure logging
15
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
16
 
17
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
18
  logging.info(f'Device selected: {device}')
 
159
 
160
  # Track the new segments and update the last transcribed time
161
  for s in segs:
162
+ logging.info(f"Processing segment with start time: {s.start} and end time: {s.end}")
163
 
164
  # Only process segments that start after the last transcribed time
165
  if s.start >= last_transcribed_time:
166
+ logging.info(f"New segment found starting at {s.start} seconds.")
167
  words = [{'start': w.start, 'end': w.end, 'word': w.word, 'probability': w.probability} for w in s.words]
168
 
169
  seg = {
 
203
  # Continuously receive and process audio chunks
204
  while True:
205
  try:
206
+ logging.info("Waiting to receive the next chunk of audio data from WebSocket.")
207
 
208
  # Receive the next chunk of audio data
209
  audio_chunk = await websocket.receive_bytes()
 
243
  await websocket.send_json({"error": str(e)})
244
  finally:
245
  logging.info("Cleaning up and closing WebSocket connection.")
 
246
 
247
 
248