[英]what is the problem with my code. it keeps on displaying this error message
i am trying to make a software that records microphone data in realtime but it keeps on coming up with an error.我正在尝试制作一个实时记录麦克风数据的软件,但它不断出现错误。 " TypeError: init () got an unexpected keyword argument '__no_builder'" i have looked through the code but cant seem to find any problems.
“ TypeError: init () got an unexpected keyword argument '__no_builder'” 我查看了代码,但似乎找不到任何问题。 i am using atom to code.
我正在使用 atom 进行编码。 there is a .kv and .py file
有一个 .kv 和 .py 文件
python file
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.garden.graph import MeshLinePlot
from kivy.clock import Clock
from threading import Thread
import audioop
import pyaudio
from kivy.core.window import Window
from kivy.lang import Builder
Window.borderless = True
def capture_mic_data():
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 = audio.rms(data,2)
if len(levels) >= 100:
levels = []
levels.append(mx)
class Logic(BoxLayout):
def __init__(self,):
super(Logic,self).__init__()
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.0001)
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 MainApp(App):
def build(self):
return Builder.load_file("main.kv")
levels =[]
capture_mic_data_thread = Thread(target = capture_mic_data)
capture_mic_data_thread.daemon = True
capture_mic_data_thread.start()
MainApp().run()
kivy file基维文件
Logic:
BoxLayout:
orientation: "vertical"
BoxLayout:
size_hint: [1,.8]
Graph:
id: graph
xlabel: "Amplitude"
ylabel: "Sample"
x_grid_label : True
y_grid_label : True
background_color : 0.429,0.3,0.423,1
x_ticks_minor : 10
x_ticks_major :5
color : 1,1,0,1
ymax: 500
ymin: 0
xmax: 100
border_color : 1,1,0,1
BoxLayout:
size_hint: [1,.1]
orientation : "horizontal"
Button:
size_hint:[0.2,1]
text: "START"
bold : True
on_press: root.start()
Button:
text: "STOP"
size_hint_x:0.2
bold :True
on_press: root.stop()
You must handle keyword arguments when you extend a class.扩展类时必须处理关键字参数。 Just add that to your
Logic
class:只需将其添加到您的
Logic
类中:
class Logic(BoxLayout):
def __init__(self, **kwargs):
super(Logic,self).__init__(**kwargs)
self.plot = MeshLinePlot(color=[1,0,0,1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.