Sound not playing correctly on loop

14 views
Skip to first unread message

Héctor Monzón

unread,
Jun 21, 2017, 10:28:52 AM6/21/17
to Kivy users support

I have a little issue here and it's breaking my head... I'm making a little app on Kivy which includes an alarm system. It bases on 4 limits, low, crit low, high and crit high, and should go "beep!" each second low or high limits are broken and "beep beep!" each second when criticals are. The code below was working perfectly until yesterday. The changes I made were: I updated kivy to 1.10.1 and installed the dev version, which I uninstalled later. However I went back to 1.9 and the error keeps on... Here's the code:


class Ingage(DragBehavior,Widget):
    name=StringProperty()
    desc=StringProperty()
    value=NumericProperty()
    rem=ObjectProperty()
    pinno=NumericProperty()
    pinmo=StringProperty()
    pin=ObjectProperty()
    ch=NumericProperty()
    h=NumericProperty()
    l=NumericProperty()
    cl=NumericProperty()
    tone=ObjectProperty()
    note=StringProperty()

    def measure(self):
        Clock.schedule_interval(self.setbar, 60/60.)

    def setbar(self, *args):
        if self.pin.read()==None:
            self.value=0
            self.note= 'No se lee el elemento'
        else:
            a= self.ch-self.cl
            self.value = (a*self.pin.read())+self.cl
            session.query(Apoint).filter_by(AP_tag=self.name).update({'AP_read': self.value})
            if self.value >= self.ch and not self.parent.checked:
                if self.tone:
                    self.tone.play()
                    time.sleep(0.2)
                    self.tone.play()
                    self.parent.rise(self.name,self.value,4,self.desc)
            if self.value <= self.cl and not self.parent.checked:
                if self.tone:
                    self.tone.play()
                    time.sleep(0.2)
                    self.tone.play()
                    self.parent.rise(self.name,self.value,2,self.desc)
            if self.value < self.l and not self.parent.checked:
                if self.tone:
                    self.tone.play()
                    self.parent.rise(self.name,self.value,1, self.desc)
            if self.value > self.h and not self.parent.checked:
                if self.tone:
                    self.tone.play()
                    self.parent.rise(self.name,self.value,3,self.desc)

Now, the issue is: instead of playing every second, the sound plays every 3 seconds! I made self.parent.rise just print something to test the loop, and it prints it every second as it should, yet the sound still plays every 3 seconds. What's going on?!

Bill Janssen

unread,
Jun 24, 2017, 11:18:27 PM6/24/17
to Kivy users support
That's pretty opaque code.  Not sure what's wrong, but you should never use time.sleep() in conjunction with Kivy -- it screws up the clock.  If you really want someone to look at it, you should probably post a complete app, so we could try it out.

Bill
Reply all
Reply to author
Forward
0 new messages