Project

Profile

Help

Revision 8d408f2d

Added by Vincent Le Goff over 4 years ago

Add a simple caching system for the #play function

View differences:

src/sharp/functions/play.py
41 41

  
42 42
    """
43 43

  
44
    def init(self):
45
        """Initialize the cache of sounds."""
46
        self.cache = {}
47

  
44 48
    def run(self, filename):
45 49
        """Say the text."""
46
        sound = mixer.Sound(filename)
50
        if filename in self.cache:
51
            sound = self.cache[filename]
52
        else:
53
            sound = mixer.Sound(filename)
54
            self.cache[filename] = sound
55

  
47 56
        sound.play()

Also available in: Unified diff