ciyidogan commited on
Commit
855e594
Β·
verified Β·
1 Parent(s): 65db296

Update websocket_handler.py

Browse files
Files changed (1) hide show
  1. websocket_handler.py +36 -10
websocket_handler.py CHANGED
@@ -376,19 +376,45 @@ async def handle_audio_chunk(websocket: WebSocket, session: RealtimeSession, mes
376
 
377
  # Stream to STT if available
378
  if session.stt_manager and session.state == ConversationState.LISTENING:
379
- async for result in session.stt_manager.stream_audio(decoded_audio):
380
- # Send transcription updates
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  await websocket.send_json({
382
- "type": "transcription",
383
- "text": result.text,
384
- "is_final": result.is_final,
385
- "confidence": result.confidence
386
  })
387
 
388
- if result.is_final:
389
- session.current_transcription = result.text
390
- log_info(f"πŸ“ Final transcription: {result.text}", session_id=session.session.session_id)
391
-
392
  # Process if silence detected and we have transcription
393
  if silence_duration > session.silence_threshold_ms and session.current_transcription:
394
  log_info(
 
376
 
377
  # Stream to STT if available
378
  if session.stt_manager and session.state == ConversationState.LISTENING:
379
+ # Ensure streaming is active
380
+ if not session.is_streaming:
381
+ log_warning(f"⚠️ STT manager exists but streaming not active", session_id=session.session.session_id)
382
+ # Try to restart streaming
383
+ stt_initialized = await session.initialize_stt()
384
+ if not stt_initialized:
385
+ await websocket.send_json({
386
+ "type": "error",
387
+ "error_type": "stt_error",
388
+ "message": "STT streaming not available"
389
+ })
390
+ return
391
+
392
+ try:
393
+ log_debug(f"🎀 Streaming audio chunk to STT, size: {len(decoded_audio)} bytes", session_id=session.session.session_id)
394
+
395
+ async for result in session.stt_manager.stream_audio(decoded_audio):
396
+ log_debug(f"πŸ“ STT result: {result.text}, final: {result.is_final}", session_id=session.session.session_id)
397
+
398
+ # Send transcription updates
399
+ await websocket.send_json({
400
+ "type": "transcription",
401
+ "text": result.text,
402
+ "is_final": result.is_final,
403
+ "confidence": result.confidence
404
+ })
405
+
406
+ if result.is_final:
407
+ session.current_transcription = result.text
408
+ log_info(f"πŸ“ Final transcription: {result.text}", session_id=session.session.session_id)
409
+
410
+ except Exception as e:
411
+ log_error(f"❌ STT streaming error", error=str(e), traceback=traceback.format_exc(), session_id=session.session.session_id)
412
  await websocket.send_json({
413
+ "type": "error",
414
+ "error_type": "stt_error",
415
+ "message": f"STT error: {str(e)}"
 
416
  })
417
 
 
 
 
 
418
  # Process if silence detected and we have transcription
419
  if silence_duration > session.silence_threshold_ms and session.current_transcription:
420
  log_info(