本文整理汇总了Python中pygame.mixer.init方法的典型用法代码示例。如果您正苦于以下问题:Python mixer.init方法的具体用法?Python mixer.init怎么用?Python mixer.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.mixer
的用法示例。
在下文中一共展示了mixer.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sound_unicode
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def test_sound_unicode(self):
"""test non-ASCII unicode path"""
mixer.init()
import shutil
ep = unicode_(example_path('data'))
temp_file = os.path.join(ep, u'你好.wav')
org_file = os.path.join(ep, u'house_lo.wav')
shutil.copy(org_file, temp_file)
try:
with open(temp_file, 'rb') as f:
pass
except IOError:
raise unittest.SkipTest('the path cannot be opened')
try:
sound = mixer.Sound(temp_file)
del sound
finally:
os.remove(temp_file)
示例2: test_get_init__returns_exact_values_used_for_init
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def test_get_init__returns_exact_values_used_for_init(self):
# fix in 1.9 - I think it's a SDL_mixer bug.
# TODO: When this bug is fixed, testing through every combination
# will be too slow so adjust as necessary, at the moment it
# breaks the loop after first failure
for init_conf in CONFIGS:
frequency, size, channels
if (frequency, size) == (22050, 16):
continue
mixer.init(frequency, size, channels)
mixer_conf = mixer.get_init()
self.assertEqual(init_conf, mixer_conf)
mixer.quit()
示例3: _init_pygame
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def _init_pygame(self):
logging.info("INFO: loading pygame mixer")
mixer.pre_init(44100, -16, 2, 2048)
mixer.init()
示例4: play_sound
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def play_sound(self, input, streamer='pygame'):
"""Plays a sound
Args:
input (str): Input file
streamer (str, optional): Streamer to use to play audio. Defaults to 'pygame'.
Raises:
NotImplementedError: `streamer` not defined
"""
logger.warning('Playing sound {}'.format(input))
if streamer == 'pygame':
from pygame import mixer
mixer.pre_init(44100, -16, 1, 512)
mixer.init()
mixer.music.load(input)
mixer.music.play()
while mixer.music.get_busy() == True:
continue
elif streamer == 'playsound':
from playsound import playsound
playsound(input)
elif streamer == 'os':
import subprocess
subprocess.call(['omxplayer', input])
elif streamer == 'none':
return
else:
raise NotImplementedError
示例5: speak_pygame
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def speak_pygame(self):
mixer.init()
mixer.pause()
mixer.music.load(self.speak_result)
mixer.music.play()
self.hibernate()
mixer.music.stop()
mixer.unpause()
mixer.quit()
示例6: door_chime
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def door_chime(self):
mixer.init()
mixer.music.load(dirname(__file__) + '/sounds/door_chime.mp3')
mixer.music.set_volume(self._settings.get('voice_volume', 100) / 100)
mixer.music.play()
示例7: start_siren
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def start_siren(self):
mixer.init()
mixer.music.load(dirname(__file__) + '/sounds/siren.mp3')
mixer.music.set_volume(self._settings.get('siren_volume', 100) / 100)
mixer.music.play(-1)
示例8: __init__
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def __init__(self, **kwargs):
mixer.init(frequency=44100, size=-16, channels=2, buffer=4096)
mixer.music.load(settings.MUSIC)
self.paused = True
self.pause_time = 0
self.initialized = False
super().__init__(**kwargs)
示例9: right
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def right(self):
mixer.init()
mixer.music.load('right.mp3')
mixer.music.play()
示例10: left
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def left(self):
mixer.init()
mixer.music.load('left.mp3')
mixer.music.play()
示例11: stop_left
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def stop_left(self):
mixer.init()
mixer.music.load('stop_left.mp3')
mixer.music.play()
示例12: stop_right
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def stop_right(self):
mixer.init()
mixer.music.load('stop_right.mp3')
mixer.music.play()
示例13: peopleOnRight
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def peopleOnRight(self):
mixer.init()
mixer.music.load('face_right.mp3')
mixer.music.play()
示例14: sound
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def sound(error=False):
mixer.init()
mixer.music.load(notify.sound_warn if error else notify.sound_info)
mixer.music.play()
示例15: _play_audio
# 需要导入模块: from pygame import mixer [as 别名]
# 或者: from pygame.mixer import init [as 别名]
def _play_audio(self):
"""Play the audio sample."""
if not self._paused:
if self._first_call:
self._first_call = False
mixer.init(48000, -16, 1, 1024)
mixer.music.load(self._audio_file)
self._set_volume()
self._set_max_progress_bar()
mixer.music.play()
else:
mixer.music.unpause()
self._paused = False
self._timer.start(self._TIME_STEP)
self._enable_buttons(False, True, True)