From 7555429433b86fc6c49b5cc5bb6b840a23430a3e Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 18 Sep 2025 15:17:28 -0400 Subject: [PATCH] Fix for dialog sound. --- speech.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/speech.py b/speech.py index 2b8a0ea..cd8910a 100644 --- a/speech.py +++ b/speech.py @@ -265,7 +265,7 @@ def _play_dialog_sound(entry, dialog_config, sounds): Args: entry (dict): Dialog entry that may have a sound dialog_config (dict): Dialog configuration that may have a default sound - sounds: Sound system for playing audio files + sounds: Sound system (either Sound class instance or dictionary of sounds) """ if not sounds: return @@ -285,20 +285,25 @@ def _play_dialog_sound(entry, dialog_config, sounds): if sound_to_play: try: - # Check if sound exists in the sound system + # Handle both Sound class instances and sound dictionaries if hasattr(sounds, 'sounds') and sound_to_play in sounds.sounds: + # Sound class instance (like from libstormgames Sound class) sound_obj = sounds.sounds[sound_to_play] - # Play the sound channel = sound_obj.play() - # Wait for the sound to finish sound_duration = sound_obj.get_length() if sound_duration > 0: - pygame.time.wait(int(sound_duration * 1000)) # Convert to milliseconds + pygame.time.wait(int(sound_duration * 1000)) + elif isinstance(sounds, dict) and sound_to_play in sounds: + # Dictionary of pygame sound objects (like from initialize_gui) + sound_obj = sounds[sound_to_play] + channel = sound_obj.play() + sound_duration = sound_obj.get_length() + if sound_duration > 0: + pygame.time.wait(int(sound_duration * 1000)) elif hasattr(sounds, 'play'): # Try using a play method if available sounds.play(sound_to_play) - # If we can't get duration, add a small delay - pygame.time.wait(500) # 0.5 second default delay + pygame.time.wait(500) # Default delay if can't get duration except Exception: # Sound missing or error - continue silently without crashing pass