Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
aab7acf
1
Parent(s):
153f836
.name remove
Browse files
client.py
CHANGED
@@ -22,11 +22,11 @@ async def send_audio(websocket):
|
|
22 |
#print(f"Received audio chunk of size {len(chunk)} bytes.")
|
23 |
|
24 |
# Send buffered audio data once it's large enough
|
25 |
-
if len(audio_buffer) >= buffer_size:
|
26 |
-
|
27 |
#print(f"Sent {len(audio_buffer)} bytes of audio data.")
|
28 |
-
|
29 |
-
|
30 |
|
31 |
print("Finished sending audio.")
|
32 |
else:
|
|
|
22 |
#print(f"Received audio chunk of size {len(chunk)} bytes.")
|
23 |
|
24 |
# Send buffered audio data once it's large enough
|
25 |
+
#if len(audio_buffer) >= buffer_size:
|
26 |
+
await websocket.send(audio_buffer)
|
27 |
#print(f"Sent {len(audio_buffer)} bytes of audio data.")
|
28 |
+
audio_buffer.clear()
|
29 |
+
await asyncio.sleep(0.01)
|
30 |
|
31 |
print("Finished sending audio.")
|
32 |
else:
|
infer.py
CHANGED
@@ -144,7 +144,7 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
144 |
|
145 |
while True:
|
146 |
try:
|
147 |
-
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
|
148 |
logging.info(f"Temporary audio file created at {temp_audio_file.name}")
|
149 |
# Receive the next chunk of audio data
|
150 |
audio_chunk = await websocket.receive_bytes()
|
@@ -161,10 +161,8 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
161 |
chunk_duration = len(audio_chunk) / (16000 * 2) # Assuming 16kHz mono WAV (2 bytes per sample)
|
162 |
accumulated_audio_time += chunk_duration
|
163 |
|
164 |
-
partial_result = await transcribe_core_ws(temp_audio_file
|
165 |
accumulated_audio_time = 0 # Reset the accumulated audio time
|
166 |
-
|
167 |
-
|
168 |
await websocket.send_json(partial_result)
|
169 |
|
170 |
except WebSocketDisconnect:
|
|
|
144 |
|
145 |
while True:
|
146 |
try:
|
147 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file: ##new temp file for every chunk
|
148 |
logging.info(f"Temporary audio file created at {temp_audio_file.name}")
|
149 |
# Receive the next chunk of audio data
|
150 |
audio_chunk = await websocket.receive_bytes()
|
|
|
161 |
chunk_duration = len(audio_chunk) / (16000 * 2) # Assuming 16kHz mono WAV (2 bytes per sample)
|
162 |
accumulated_audio_time += chunk_duration
|
163 |
|
164 |
+
partial_result = await transcribe_core_ws(temp_audio_file)
|
165 |
accumulated_audio_time = 0 # Reset the accumulated audio time
|
|
|
|
|
166 |
await websocket.send_json(partial_result)
|
167 |
|
168 |
except WebSocketDisconnect:
|