Spaces:
Sleeping
Sleeping
Commit
·
75d4ff4
1
Parent(s):
4e75e2b
process_audio_chunk result is not sent back to the client
Browse files- inference.py +16 -0
- ui.py +30 -0
inference.py
CHANGED
|
@@ -245,12 +245,27 @@ async def ws_inference(websocket: WebSocket):
|
|
| 245 |
# Process audio chunk
|
| 246 |
result = diart.process_audio_chunk(data)
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
# Log processing result (optional)
|
| 249 |
if connection_stats["total_audio_chunks"] % 100 == 0: # Log every 100 chunks
|
| 250 |
logger.debug(f"Processed {connection_stats['total_audio_chunks']} audio chunks")
|
| 251 |
|
| 252 |
elif not diart:
|
| 253 |
logger.warning("Received audio data but diarization system not initialized")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
except Exception as e:
|
| 256 |
logger.error(f"Error processing audio chunk: {e}")
|
|
@@ -258,6 +273,7 @@ async def ws_inference(websocket: WebSocket):
|
|
| 258 |
error_message = json.dumps({
|
| 259 |
"type": "error",
|
| 260 |
"message": "Error processing audio",
|
|
|
|
| 261 |
"timestamp": time.time()
|
| 262 |
})
|
| 263 |
await websocket.send_text(error_message)
|
|
|
|
| 245 |
# Process audio chunk
|
| 246 |
result = diart.process_audio_chunk(data)
|
| 247 |
|
| 248 |
+
# Send processing result back to client
|
| 249 |
+
if result:
|
| 250 |
+
result_message = json.dumps({
|
| 251 |
+
"type": "processing_result",
|
| 252 |
+
"timestamp": time.time(),
|
| 253 |
+
"data": result
|
| 254 |
+
})
|
| 255 |
+
await websocket.send_text(result_message)
|
| 256 |
+
|
| 257 |
# Log processing result (optional)
|
| 258 |
if connection_stats["total_audio_chunks"] % 100 == 0: # Log every 100 chunks
|
| 259 |
logger.debug(f"Processed {connection_stats['total_audio_chunks']} audio chunks")
|
| 260 |
|
| 261 |
elif not diart:
|
| 262 |
logger.warning("Received audio data but diarization system not initialized")
|
| 263 |
+
error_message = json.dumps({
|
| 264 |
+
"type": "error",
|
| 265 |
+
"message": "Diarization system not initialized",
|
| 266 |
+
"timestamp": time.time()
|
| 267 |
+
})
|
| 268 |
+
await websocket.send_text(error_message)
|
| 269 |
|
| 270 |
except Exception as e:
|
| 271 |
logger.error(f"Error processing audio chunk: {e}")
|
|
|
|
| 273 |
error_message = json.dumps({
|
| 274 |
"type": "error",
|
| 275 |
"message": "Error processing audio",
|
| 276 |
+
"details": str(e),
|
| 277 |
"timestamp": time.time()
|
| 278 |
})
|
| 279 |
await websocket.send_text(error_message)
|
ui.py
CHANGED
|
@@ -187,11 +187,41 @@ def build_ui():
|
|
| 187 |
}
|
| 188 |
break;
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
case 'connection':
|
| 191 |
console.log('Connection status:', message.status);
|
| 192 |
updateStatus(message.status === 'connected' ? 'connected' : 'warning');
|
| 193 |
break;
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
case 'conversation_update':
|
| 196 |
if (message.conversation_html) {
|
| 197 |
document.getElementById("conversation").innerHTML = message.conversation_html;
|
|
|
|
| 187 |
}
|
| 188 |
break;
|
| 189 |
|
| 190 |
+
case 'processing_result':
|
| 191 |
+
// Handle individual audio chunk processing result
|
| 192 |
+
console.log('Processing result:', message.data);
|
| 193 |
+
|
| 194 |
+
// Update status info if needed
|
| 195 |
+
if (message.data && message.data.status === "processed") {
|
| 196 |
+
const statusElem = document.getElementById('status-text');
|
| 197 |
+
if (statusElem) {
|
| 198 |
+
const speakerId = message.data.speaker_id !== undefined ?
|
| 199 |
+
`Speaker ${message.data.speaker_id + 1}` : '';
|
| 200 |
+
|
| 201 |
+
if (speakerId) {
|
| 202 |
+
statusElem.textContent = `Connected - ${speakerId} active`;
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
} else if (message.data && message.data.status === "error") {
|
| 206 |
+
updateStatus('error', message.data.message || 'Processing error');
|
| 207 |
+
}
|
| 208 |
+
break;
|
| 209 |
+
|
| 210 |
case 'connection':
|
| 211 |
console.log('Connection status:', message.status);
|
| 212 |
updateStatus(message.status === 'connected' ? 'connected' : 'warning');
|
| 213 |
break;
|
| 214 |
|
| 215 |
+
case 'connection_established':
|
| 216 |
+
console.log('Connection established:', message);
|
| 217 |
+
updateStatus('connected');
|
| 218 |
+
|
| 219 |
+
// If initial conversation is provided, display it
|
| 220 |
+
if (message.conversation) {
|
| 221 |
+
document.getElementById("conversation").innerHTML = message.conversation;
|
| 222 |
+
}
|
| 223 |
+
break;
|
| 224 |
+
|
| 225 |
case 'conversation_update':
|
| 226 |
if (message.conversation_html) {
|
| 227 |
document.getElementById("conversation").innerHTML = message.conversation_html;
|