所以,当我试图为github运行一个示例代码,创建麦克风数据的实时绘图时,我遇到了这个错误。错误为TypeError:init()获取了意外的关键字参数“\uu no\u builder”
我已尝试将 def __init__(self,): super(Logic, self).__init__()
in更改为 def __init__(self, **kwargs): super(Logic, self).__init__(**kwargs)
。这是堆栈溢出中的某个人建议的,但不起作用。我正在这里发送完整的代码。。。
“”“使用kivy实时绘制麦克风音量
“”“
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.garden.graph import Graph, MeshLinePlot
from kivy.clock import Clock
from threading import Thread
import audioop
import pyaudio
def get_microphone_level():
"""
source: http://stackoverflow.com/questions/26478315/getting-volume-levels-from-pyaudio-for-use-in-arduino
audioop.max alternative to audioop.rms
"""
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
p = pyaudio.PyAudio()
s = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=chunk)
global levels
while True:
data = s.read(chunk)
mx = audioop.rms(data, 2)
if len(levels) >= 100:
levels = []
levels.append(mx)
class Logic(BoxLayout):
def __init__(self, **kwargs):
super(Logic, self).__init__(**kwargs)
self.plot = MeshLinePlot(color=[1, 0, 0, 1])
def start(self):
self.ids.graph.add_plot(self.plot)
Clock.schedule_interval(self.get_value, 0.001)
def stop(self):
Clock.unschedule(self.get_value)
def get_value(self, dt):
self.plot.points = [(i, j/5) for i, j in enumerate(levels)]
class RealTimeMicrophone(App):
def build(self):
return Builder.load_file("look.kv")
if __name__ == "__main__":
levels = [] # store levels of microphone
get_level_thread = Thread(target = get_microphone_level)
get_level_thread.daemon = True
get_level_thread.start()
RealTimeMicrophone().run()
目前没有回答
相关问题 更多 >
编程相关推荐