Revision 4d2b7a46
Added by Vincent Le Goff over 4 years ago
src/sharp/functions/play.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
"""Module containing the Play function class.""" |
30 | 30 |
|
31 |
from pygame import mixer |
|
32 |
mixer.init() |
|
31 |
import winsound |
|
33 | 32 |
|
34 | 33 |
from sharp import Function |
35 | 34 |
|
... | ... | |
41 | 40 |
|
42 | 41 |
""" |
43 | 42 |
|
44 |
def init(self): |
|
45 |
"""Initialize the cache of sounds.""" |
|
46 |
self.cache = {} |
|
47 |
|
|
48 | 43 |
def run(self, filename): |
49 | 44 |
"""Say the text.""" |
50 |
if filename in self.cache: |
|
51 |
sound = self.cache[filename] |
|
52 |
else: |
|
53 |
sound = mixer.Sound(filename) |
|
54 |
self.cache[filename] = sound |
|
55 |
|
|
56 |
sound.play() |
|
45 |
winsound.PlaySound(filename, winsound.SND_ASYNC | winsound.SND_FILENAME) |
Also available in: Unified diff
Replace pygame by winsound to play sounds (faster although not portable)