From 943e2acf53e3a20ffbae3890faf801d86aafa9e4 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 14 Feb 2025 23:58:26 -0500 Subject: [PATCH] Try to keep speech form stuttering with status keys. --- __init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/__init__.py b/__init__.py index c91ba0a..10fb269 100755 --- a/__init__.py +++ b/__init__.py @@ -53,6 +53,10 @@ bgmVolume = 0.75 # Default background music volume sfxVolume = 1.0 # Default sound effects volume masterVolume = 1.0 # Default master volume +# Handle speech delays so we don't get stuttering +_lastSpoken = {"text": None, "time": 0} +_speechDelay = 250 # ms + class Scoreboard: """Handles high score tracking with player names.""" @@ -337,6 +341,18 @@ def speak(text, interrupt=True): text (str): Text to speak and display interrupt (bool): Whether to interrupt current speech (default: True) """ + current_time = pygame.time.get_ticks() + + # Check if this is the same text within the delay window + if (_lastSpoken["text"] == text and + current_time - _lastSpoken["time"] < _speechDelay): + return + + # Update last spoken tracking + _lastSpoken["text"] = text + _lastSpoken["time"] = current_time + + # Proceed with speech if speechProvider == "speechd": if interrupt: spd.cancel()