Fix for dialog sound.
This commit is contained in:
19
speech.py
19
speech.py
@@ -265,7 +265,7 @@ def _play_dialog_sound(entry, dialog_config, sounds):
|
|||||||
Args:
|
Args:
|
||||||
entry (dict): Dialog entry that may have a sound
|
entry (dict): Dialog entry that may have a sound
|
||||||
dialog_config (dict): Dialog configuration that may have a default 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:
|
if not sounds:
|
||||||
return
|
return
|
||||||
@@ -285,20 +285,25 @@ def _play_dialog_sound(entry, dialog_config, sounds):
|
|||||||
|
|
||||||
if sound_to_play:
|
if sound_to_play:
|
||||||
try:
|
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:
|
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]
|
sound_obj = sounds.sounds[sound_to_play]
|
||||||
# Play the sound
|
|
||||||
channel = sound_obj.play()
|
channel = sound_obj.play()
|
||||||
# Wait for the sound to finish
|
|
||||||
sound_duration = sound_obj.get_length()
|
sound_duration = sound_obj.get_length()
|
||||||
if sound_duration > 0:
|
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'):
|
elif hasattr(sounds, 'play'):
|
||||||
# Try using a play method if available
|
# Try using a play method if available
|
||||||
sounds.play(sound_to_play)
|
sounds.play(sound_to_play)
|
||||||
# If we can't get duration, add a small delay
|
pygame.time.wait(500) # Default delay if can't get duration
|
||||||
pygame.time.wait(500) # 0.5 second default delay
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# Sound missing or error - continue silently without crashing
|
# Sound missing or error - continue silently without crashing
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user