Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
b85baaf
1
Parent(s):
5a62402
trying to get logs on hf
Browse files
client.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import asyncio
|
|
|
|
|
|
|
2 |
import websockets
|
3 |
import requests
|
4 |
import ssl
|
@@ -7,21 +10,24 @@ import logging
|
|
7 |
import sys
|
8 |
|
9 |
# Parameters for reading and sending the audio
|
10 |
-
AUDIO_FILE_URL = "https://raw.githubusercontent.com/AshDavid12/runpod-serverless-forked/main/test_hebrew.wav" # Use WAV file
|
11 |
-
|
12 |
|
13 |
|
14 |
|
15 |
# Set up logging
|
16 |
-
logging.basicConfig(level=logging.
|
17 |
handlers=[logging.StreamHandler(sys.stdout)], force=True)
|
18 |
logger = logging.getLogger(__name__)
|
19 |
|
20 |
async def send_receive():
|
21 |
uri = "wss://gigaverse-ivrit-ai-streaming.hf.space/ws" # Update with your server's address if needed
|
|
|
|
|
|
|
22 |
logger.info(f"Connecting to server at {uri}")
|
23 |
try:
|
24 |
-
async with websockets.connect(uri) as websocket:
|
25 |
logger.info("WebSocket connection established")
|
26 |
# Start tasks for sending and receiving
|
27 |
send_task = asyncio.create_task(send_audio(websocket))
|
@@ -31,49 +37,39 @@ async def send_receive():
|
|
31 |
logger.error(f"WebSocket connection error: {e}")
|
32 |
|
33 |
async def send_audio(websocket):
|
34 |
-
wav_file =
|
35 |
logger.info(f"Opening WAV file: {wav_file}")
|
36 |
|
37 |
try:
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
duration = nframes / framerate
|
47 |
-
logger.debug(f"WAV file parameters: channels={channels}, sample_width={sampwidth}, framerate={framerate}, frames={nframes}, duration={duration:.2f}s")
|
48 |
-
|
49 |
-
# Ensure the WAV file has the expected parameters
|
50 |
-
if channels != 1 or sampwidth != 2 or framerate != 16000:
|
51 |
-
logger.error("WAV file must be mono channel, 16-bit samples, 16kHz sampling rate")
|
52 |
-
return
|
53 |
-
|
54 |
-
chunk_duration = 0.1 # in seconds
|
55 |
-
chunk_size = int(framerate * chunk_duration)
|
56 |
-
logger.info(f"Starting to send audio data in chunks of {chunk_duration}s ({chunk_size} frames)")
|
57 |
|
58 |
total_chunks = 0
|
59 |
total_bytes_sent = 0
|
60 |
|
|
|
61 |
while True:
|
62 |
-
|
63 |
-
if not
|
64 |
-
logger.info("End of WAV file reached")
|
65 |
break
|
66 |
-
await websocket.send(
|
67 |
total_chunks += 1
|
68 |
-
total_bytes_sent += len(
|
69 |
-
logger.debug(f"Sent chunk {total_chunks}: {len(
|
70 |
-
await asyncio.sleep(
|
|
|
|
|
71 |
|
72 |
-
logger.info(f"Finished sending audio data: {total_chunks} chunks sent, total bytes sent: {total_bytes_sent}")
|
73 |
except Exception as e:
|
74 |
logger.error(f"Send audio error: {e}")
|
|
|
75 |
finally:
|
76 |
-
wf.close()
|
77 |
logger.info("WAV file closed")
|
78 |
|
79 |
async def receive_transcriptions(websocket):
|
|
|
1 |
import asyncio
|
2 |
+
import io
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
import websockets
|
6 |
import requests
|
7 |
import ssl
|
|
|
10 |
import sys
|
11 |
|
12 |
# Parameters for reading and sending the audio
|
13 |
+
#AUDIO_FILE_URL = "https://raw.githubusercontent.com/AshDavid12/runpod-serverless-forked/main/test_hebrew.wav" # Use WAV file
|
14 |
+
AUDIO_FILE_URL = "https://raw.githubusercontent.com/AshDavid12/hugging_face_ivrit_streaming/main/long_hebrew.wav"
|
15 |
|
16 |
|
17 |
|
18 |
# Set up logging
|
19 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s',
|
20 |
handlers=[logging.StreamHandler(sys.stdout)], force=True)
|
21 |
logger = logging.getLogger(__name__)
|
22 |
|
23 |
async def send_receive():
|
24 |
uri = "wss://gigaverse-ivrit-ai-streaming.hf.space/ws" # Update with your server's address if needed
|
25 |
+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
26 |
+
ssl_context.check_hostname = False
|
27 |
+
ssl_context.verify_mode = ssl.CERT_NONE
|
28 |
logger.info(f"Connecting to server at {uri}")
|
29 |
try:
|
30 |
+
async with websockets.connect(uri,ssl=ssl_context) as websocket:
|
31 |
logger.info("WebSocket connection established")
|
32 |
# Start tasks for sending and receiving
|
33 |
send_task = asyncio.create_task(send_audio(websocket))
|
|
|
37 |
logger.error(f"WebSocket connection error: {e}")
|
38 |
|
39 |
async def send_audio(websocket):
|
40 |
+
wav_file = AUDIO_FILE_URL # Replace with the path to your WAV file
|
41 |
logger.info(f"Opening WAV file: {wav_file}")
|
42 |
|
43 |
try:
|
44 |
+
# Download the WAV file
|
45 |
+
response = requests.get(wav_file)
|
46 |
+
response.raise_for_status()
|
47 |
+
wav_bytes = io.BytesIO(response.content)
|
48 |
+
|
49 |
+
|
50 |
+
# Send audio data in chunks directly from the WAV file
|
51 |
+
chunk_size = 1024 # Sending data in chunks of 3200 bytes, which can be adjusted
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
total_chunks = 0
|
54 |
total_bytes_sent = 0
|
55 |
|
56 |
+
# While loop to send audio data chunk by chunk
|
57 |
while True:
|
58 |
+
chunk = wav_bytes.read(chunk_size)
|
59 |
+
if not chunk:
|
|
|
60 |
break
|
61 |
+
await websocket.send(chunk)
|
62 |
total_chunks += 1
|
63 |
+
total_bytes_sent += len(chunk)
|
64 |
+
logger.debug(f"Sent chunk {total_chunks}: {len(chunk)} bytes")
|
65 |
+
await asyncio.sleep(0.1) # Simulate real-time streamin
|
66 |
+
logger.info(
|
67 |
+
f"Finished sending audio data: {total_chunks} chunks sent, total bytes sent: {total_bytes_sent}")
|
68 |
|
|
|
69 |
except Exception as e:
|
70 |
logger.error(f"Send audio error: {e}")
|
71 |
+
|
72 |
finally:
|
|
|
73 |
logger.info("WAV file closed")
|
74 |
|
75 |
async def receive_transcriptions(websocket):
|
infer.py
CHANGED
@@ -15,7 +15,7 @@ import sys
|
|
15 |
import asyncio
|
16 |
|
17 |
# Configure logging
|
18 |
-
logging.basicConfig(level=logging.
|
19 |
handlers=[logging.StreamHandler(sys.stdout)], force=True)
|
20 |
logger = logging.getLogger(__name__)
|
21 |
#logging.getLogger("asyncio").setLevel(logging.DEBUG)
|
@@ -129,6 +129,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
129 |
await websocket.accept()
|
130 |
client_ip = websocket.client.host
|
131 |
logger.info(f"Client connected: {client_ip}")
|
|
|
132 |
try:
|
133 |
await process_audio_stream(websocket)
|
134 |
except WebSocketDisconnect:
|
|
|
15 |
import asyncio
|
16 |
|
17 |
# Configure logging
|
18 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s',
|
19 |
handlers=[logging.StreamHandler(sys.stdout)], force=True)
|
20 |
logger = logging.getLogger(__name__)
|
21 |
#logging.getLogger("asyncio").setLevel(logging.DEBUG)
|
|
|
129 |
await websocket.accept()
|
130 |
client_ip = websocket.client.host
|
131 |
logger.info(f"Client connected: {client_ip}")
|
132 |
+
sys.stdout.flush()
|
133 |
try:
|
134 |
await process_audio_stream(websocket)
|
135 |
except WebSocketDisconnect:
|