In [23]: sound = pygame.mixer.Sound('FishPolka.mid')
In [24]: sr = sound.get_raw()
-
AttributeError Traceback (most recent call last)
E:\Documents and Settings\Me\Desktop\<ipython console> in <module>()
AttributeError: 'Sound' object has no attribute 'get_raw'
In [25]: sound.g
sound.get_buffer sound.get_length sound.get_num_channels sound.get_volume
# create a sound from NumPy array of file
snd = pygame.mixer.Sound(my_sound_source)
# open new wave file
sfile = wave.open('pure_tone.wav', 'w')
# set the parameters
sfile.setframerate(SAMPLINGFREQ)
sfile.setnchannels(NCHANNELS)
sfile.setsampwidth(2)
# write raw PyGame sound buffer to wave file
sfile.writeframesraw(snd.get_buffer().raw)
# close file
sfile.close()
我从来没试过这个,所以我只是猜测它可能有用。
pygame.mixer.Sound
对象有一个名为get_raw()
的函数,它在python3.x中返回一个字节数组,在python2.x中返回一个字符串。我想您可以使用这个字节数组来保存声音。在{a1}
我想应该是这样的:
这不是一个问题。这是一个评论,因为我上面写的评论不清楚,因为我不知道如何使回车工作。在
我的意见是:上述解决方案行不通。在
这是ipython的一个测试的节选。在
您的问题已经有将近两年的历史了,但是万一人们还在寻找答案:您可以使用
wave
模块(原生Python)来保存PyGame声音实例。在关于GitHub的更多信息和示例:https://github.com/esdalmaijer/Save_PyGame_Sound。在
相关问题 更多 >
编程相关推荐