MCPcopy Create free account
hub / github.com/KoljaB/RealtimeVoiceChat / TranscriptionCallbacks

Class TranscriptionCallbacks

code/server.py:517–867  ·  view source on GitHub ↗

Manages state and callbacks for a single WebSocket connection's transcription lifecycle. This class holds connection-specific state flags (like TTS status, user interruption) and implements callback methods triggered by the `AudioInputProcessor` and `SpeechPipelineManager`. It send

Source from the content-addressed store, hash-verified

515# Callback class to handle transcription events
516# --------------------------------------------------------------------
517class TranscriptionCallbacks:
518 """
519 Manages state and callbacks for a single WebSocket connection's transcription lifecycle.
520
521 This class holds connection-specific state flags (like TTS status, user interruption)
522 and implements callback methods triggered by the `AudioInputProcessor` and
523 `SpeechPipelineManager`. It sends messages back to the client via the provided
524 `message_queue` and manages interaction logic like interruptions and final answer delivery.
525 It also includes a threaded worker to handle abort checks based on partial transcription.
526 """
527 def __init__(self, app: FastAPI, message_queue: asyncio.Queue):
528 """
529 Initializes the TranscriptionCallbacks instance for a WebSocket connection.
530
531 Args:
532 app: The FastAPI application instance (to access global components).
533 message_queue: An asyncio queue for sending messages back to the client.
534 """
535 self.app = app
536 self.message_queue = message_queue
537 self.final_transcription = ""
538 self.abort_text = ""
539 self.last_abort_text = ""
540
541 # Initialize connection-specific state flags here
542 self.tts_to_client: bool = False
543 self.user_interrupted: bool = False
544 self.tts_chunk_sent: bool = False
545 self.tts_client_playing: bool = False
546 self.interruption_time: float = 0.0
547
548 # These were already effectively instance variables or reset logic existed
549 self.silence_active: bool = True
550 self.is_hot: bool = False
551 self.user_finished_turn: bool = False
552 self.synthesis_started: bool = False
553 self.assistant_answer: str = ""
554 self.final_assistant_answer: str = ""
555 self.is_processing_potential: bool = False
556 self.is_processing_final: bool = False
557 self.last_inferred_transcription: str = ""
558 self.final_assistant_answer_sent: bool = False
559 self.partial_transcription: str = "" # Added for clarity
560
561 self.reset_state() # Call reset to ensure consistency
562
563 self.abort_request_event = threading.Event()
564 self.abort_worker_thread = threading.Thread(target=self._abort_worker, name="AbortWorker", daemon=True)
565 self.abort_worker_thread.start()
566
567
568 def reset_state(self):
569 """Resets connection-specific state flags and variables to their initial values."""
570 # Reset all connection-specific state flags
571 self.tts_to_client = False
572 self.user_interrupted = False
573 self.tts_chunk_sent = False
574 # Don't reset tts_client_playing here, it reflects client state reports

Callers 1

websocket_endpointFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected