From fdf1de5180da4bc2c555cdfc343203f6b97185ff Mon Sep 17 00:00:00 2001 From: Jatin K Malik Date: Thu, 5 Feb 2026 18:47:38 -0800 Subject: [PATCH] fix(transcription): add space after punctuation when transcribing again (#151) When transcribing text continuously (stop and start again), the new text was being injected immediately after the last character without a space. This caused issues like "Hello world.This is a test" instead of "Hello world. This is a test". Fix: - Check if the last injected text ends with punctuation or other characters that typically need a space after them (., ,, !, ?, ;, :, quotes, etc.) - If yes, add a space before injecting the new text - Log when space is added for debugging Characters requiring space: - Punctuation: . , ! ? ; : ) ] } - _ - Quotes: " ' Closes #151 --- src/vocalinux/main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/vocalinux/main.py b/src/vocalinux/main.py index 64ea25a..7e4d749 100644 --- a/src/vocalinux/main.py +++ b/src/vocalinux/main.py @@ -219,7 +219,36 @@ def main(): # Create a wrapper function to track injected text for action handler def text_callback_wrapper(text: str): """Wrapper to track injected text and handle it.""" - success = text_system.inject_text(text) + # Check if we need to add a space before the new text + text_to_inject = text + + # Punctuation and characters that typically need a space after them + chars_needing_space = { + ".", + ",", + "!", + "?", + ";", + ":", + ")", + "]", + "}", + "-", + "_", + # Also quotes + '"', + "'", + } + + # If last injected text exists and ends with a character that needs space, + # add a space before the new text + if action_handler.last_injected_text and action_handler.last_injected_text.strip(): + last_char = action_handler.last_injected_text[-1] + if last_char in chars_needing_space: + text_to_inject = " " + text_to_inject + logger.debug(f"Added space before new text (last char: '{last_char}')") + + success = text_system.inject_text(text_to_inject) if success: action_handler.set_last_injected_text(text)