Skip to content

Add transcript reset feature on a websocket connection#423

Open
Yadav-Roshan wants to merge 1 commit intocollabora:mainfrom
Yadav-Roshan:main
Open

Add transcript reset feature on a websocket connection#423
Yadav-Roshan wants to merge 1 commit intocollabora:mainfrom
Yadav-Roshan:main

Conversation

@Yadav-Roshan
Copy link

@Yadav-Roshan Yadav-Roshan commented Feb 26, 2026

Hey,

One have to disconnect or reconnect to reset the transcript. I needed a feature to reset the transcript on already connected session. Hence, I added this feature. I hope a lot of people might require this feature who could be building voice2voice agents. Each query needs to be a fresh session.

I vibecoded some parts but verified it manually and everything is fine and it works fine too.

This is not just for a show-off contribution, this is what I needed in my application and I wanted to avoid changing source code each time I am building any new application with the same need.

I'll be glad to receive any constructive criticism.

@makaveli10 makaveli10 self-assigned this Mar 3, 2026
@makaveli10
Copy link
Collaborator

Thanks for opening the PR! taking a look into it this week

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “reset transcript” control message to the existing WebSocket session so clients can start a fresh transcription without disconnecting/reconnecting.

Changes:

  • Server: parse a JSON control frame ({"action": "RESET_TRANSCRIPT"}) from the WebSocket receive loop and trigger a per-client reset.
  • Backend: add ServeClientBase.reset_transcript() plus a TRANSCRIPT_RESET acknowledgment message back to the client.
  • Client + tests: add Client.reset_transcript() and basic unit tests for reset + ack handling.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
whisper_live/server.py Adds control-frame parsing and a “RESET” sentinel path to keep the receive loop running.
whisper_live/client.py Adds client-side reset API and logs server acknowledgment.
whisper_live/backend/base.py Introduces server-side transcript/audio state reset and sends TRANSCRIPT_RESET ack.
tests/test_server.py Adds unit tests for ServeClientBase.reset_transcript().
tests/test_client.py Adds tests for handling TRANSCRIPT_RESET ack and client reset behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

client.reset_transcript()
return "RESET"
except (UnicodeDecodeError, json.JSONDecodeError, ValueError):
pass # Not a JSON control frame; treat as audio bytes
Comment on lines 309 to +322
if frame_data == b"END_OF_AUDIO":
return False
# Handle JSON control frames (sent as text or bytes that decode to JSON)
if isinstance(frame_data, (str, bytes)):
try:
decoded = frame_data if isinstance(frame_data, str) else frame_data.decode("utf-8")
control = json.loads(decoded)
if control.get("action") == "RESET_TRANSCRIPT":
client = self.client_manager.get_client(websocket)
if client:
client.reset_transcript()
return "RESET"
except (UnicodeDecodeError, json.JSONDecodeError, ValueError):
pass # Not a JSON control frame; treat as audio bytes
client.reset_transcript()
return "RESET"
except (UnicodeDecodeError, json.JSONDecodeError, ValueError):
pass # Not a JSON control frame; treat as audio bytes
self.end_time_for_same_output = None
self.frames_np = None
self.frames_offset = 0.0
self.timestamp_offset = 0.0
Comment on lines +273 to +282
with self.lock:
self.transcript = []
self.text = []
self.current_out = ''
self.prev_out = ''
self.same_output_count = 0
self.end_time_for_same_output = None
self.frames_np = None
self.frames_offset = 0.0
self.timestamp_offset = 0.0
self.prev_out = ''
self.same_output_count = 0
self.end_time_for_same_output = None
self.frames_np = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants