def sound(path, volume = None, pan = None, frequency = None, play = True, loop = False, stream = False): """ Play a sound. Arguments: path - The path to the file. volume - The volume of the resulting sound from 0.0 to 1.0. pan - The pan of the resulting sound from -1.0 to 1.0. frequency - The frequency to play the resulting sound at. play - If True, the sound will begin playing immediately. loop - If True, play the sound repeatedly. stream - If True, retrieve the sound from the internet. """ if volume == None: volume = application.config.get('sound', 'volume') if pan == None: pan = application.config.get('sound', 'pan') if frequency == None: frequency = application.config.get('sound', 'frequency') if stream: logger.debug('Playing stream: %s.', path) sound = URLStream(path) else: m = sound_re.match(path) if m: max = m.groupdict()['max'] path = path.replace('*%s' % max, str(int(random() * int(max) + 1))) logger.debug('Playing sound: %s.', path) sound = FileStream(file = path) sound.set_volume(volume) sound.set_pan(pan) sound.set_frequency(frequency) sound.set_looping = loop if play: Thread(target = sound.play_blocking, args = [True]).start() return sound