我正在尝试使用Python为我的Raspberry Pi开发一个Simple Sound2Light应用程序。 我正在使用Ian Halpern编写的Impulse库(https://github.com/ianhalpern/Impulse)
然而,我首先尝试从音频阵列Impulse中提取3个值(Sub,Mid,Hi)。
这是代码:
#!/usr/bin/env python
import sys, os, time
import impulse
def draw ( ):
fft = True
audio_sample_array = impulse.getSnapshot( fft )
if fft:
ffted_array = list( audio_sample_array )
# start drawing spectrum
red = 0
green = 0
blue = 0
for i in range(0,20):
blue += ffted_array[i]
for i in range(21,41):
green += ffted_array[i]
for i in range(42,62):
red += ffted_array[i]
print red,
print blue,
print green
return False
def main(args):
try:
while True:
draw()
time.sleep(1)
except KeyboardInterrupt:
pass
return True
if __name__ == '__main__':
try:
import ctypes
libc = ctypes.CDLL('libc.so.6')
libc.prctl(15, os.path.split( sys.argv[ 0 ] )[ 1 ], 0, 0, 0)
except:
pass
sys.exit( main( sys.argv ) )
main( sys.argv )
然而,这段代码在我的笔记本电脑上运行得非常完美(archlinux x64 python 2.7)
[felix@felix-think impulse]$ python2 --version
Python 2.7.3
但无法在我的Rapsberry Pi(运行Raspbian)上运行
pi@raspberrypi ~/music2light $ python --version
Python 2.7.3
这是ErrorMessage
pi@raspberrypi ~/music2light $ python main.py
Traceback (most recent call last):
File "main.py", line 56, in <module>
sys.exit( main( sys.argv ) )
File "main.py", line 40, in main
draw()
File "main.py", line 21, in draw
for i in range(0,20):
RuntimeError: More keyword list entries (5) than format specifiers (1)
我尝试使用谷歌但没有发现任何内容......我发现的唯一一件事是,getargs.c文件(http://svn.python.org/projects/python/branches/release27-maint/Python/getargs.c)
引发了错误if (IS_END_OF_FORMAT(*format)) {
PyErr_Format(PyExc_RuntimeError,
"More keyword list entries (%d) than "
"format specifiers (%d)", len, i);
return cleanreturn(0, freelist);
}
先谢谢你的帮助:) 菲利克斯