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
This commit is contained in:
+30
-1
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user