def __init__(self, data, fs=None, loop=False, api=None, name=None, fixed_delay=None, api_options=None): assert AudioFormat is not None if any(x is not None for x in (api, name, fixed_delay, api_options)): raise ValueError('The Pyglet backend does not support specifying ' 'api, name, fixed_delay, or api_options') # We could maybe let Pyglet make this decision, but hopefully # people won't need to tweak the Pyglet backend anyway self.fs = 44100 if fs is None else fs super(SoundPlayer, self).__init__() _check_pyglet_audio() sms = _as_static(data, self.fs) if _new_pyglet(): self.queue(sms) self.loop = bool(loop) else: group = SourceGroup(sms.audio_format, None) group.loop = bool(loop) group.queue(sms) self.queue(group) self._ec_duration = sms._duration
def __init__(self, data, fs, loop=False): assert AudioFormat is not None super(SoundPlayer, self).__init__() _check_pyglet_audio() sms = _as_static(data, fs) group = SourceGroup(sms.audio_format, None) group.loop = bool(loop) group.queue(sms) self.queue(group)
def play_sound_once(self,soundfile,volume): if self.config.sound_switch>0: play_sound = Player() play_sound_source = load(soundfile) play_sound_group = SourceGroup(play_sound_source.audio_format, None) play_sound_group.loop = False play_sound_group.queue(play_sound_source) play_sound.queue(play_sound_group) play_sound.volume=float(volume) * self.config.sound_switch play_sound.play()
def queue(self, source): source_group = SourceGroup(source.audio_format, source.video_format) source_group.queue(source) Player.queue(self, source_group) source_group.loop = self.loop
def queue(self, source): source = self.engine[source] looper = SourceGroup(source.audio_format, None) looper.loop = True looper.queue(source) super(AmbientPlayer, self).queue(looper)