1
0
This repository has been archived on 2024-09-03. You can view files and clone it, but cannot push or open issues or pull requests.
no-cooperation/soundDataBase.py

23 lines
673 B
Python

import pygame, glob
class SoundDBase(object):
def __init__(self, path):
# Loads sounds
self.sounds = {}
self.addAdditionalDirectory(path)
def get(self, name):
return self.sounds[name]
def addAdditionalDirectory(self, path):
for sound in glob.glob(path + "\\" + "*"):
try: # Try to load the .ogg file. If it fails, move on to the next one.
key = sound[len(path) + 1: sound.rfind(".")] # Slices the string name of every sound
sound = pygame.mixer.Sound(sound) #Loads every sound
self.sounds[str(key)] = sound
except:
pass