[英]how to use pyglet to play sound in a mayavi animation?
I want to play sound using pyglet
in a mayavi animation loop, but I found that pyglet
worked not well with 'yield', which has to use in a mayavi animation.我想在 Mayavi 动画循环中使用pyglet
播放声音,但我发现pyglet
与必须在 Mayavi 动画中使用的“yield”配合得不好。 The situation is that, it just can't start a new loop when the sound played and animation done once, here are some of my codes, any ideas?情况是,当播放声音和动画完成一次时,它无法开始新的循环,这是我的一些代码,有什么想法吗?
The pyglet
can play sound in a for-loop, but can't use yield
. pyglet
可以在 for 循环中播放声音,但不能使用yield
。
@mlab.animate(delay=delays)
def animate():
f = mlab.gcf()
while True:
for i in range(frames_num):
# update sound
sound = 'shiping/shiping_%d.wav'%i
sound_adjust = pyglet.resource.media(sound, streaming=False)
sound_adjust.play()
# update scene
print('Update scene >>', time.time())
function_to_update_scene()
# with out 'yield' it works well
yield
animate()
Any other modules suggest can also be accepted.也可以接受任何其他模块建议。 The matter is that I need to update sound quickly within 20ms.问题是我需要在 20 毫秒内快速更新声音。
I at last solved this by using winsound
module.我终于通过使用winsound
模块解决了这个问题。 Using使用
winsound.PlaySound(sound, winsound.SND_FILENAME | winsound.SND_ASYNC)
to replace取代
sound_adjust = pyglet.resource.media(sound, streaming=False)
sound_adjust.play()
to play defined sound asynchronously.异步播放定义的声音。 Off course you have to import winsound
at the very beginning.当然,您必须在一开始就import winsound
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.