[PYTHON] Pepper decides the winner by measuring the size of the audience's applause

How did you write this article?

It was created because the mechanism that decided the Pepper prize at the hackathon "Business trip! Tsukurimi Lab in DMM.make AKIBA with Pepper" sponsored by Mr. Fun Kayak held at DMM.make AKIBA on October 3rd this year was interesting. I asked "Master Kawada, who doesn't know if I was doing Pepper" and he gave me a professor, so I will share it.

** By the way, I didn't get the Pepper prize at this time, but I won! Hooray. ** **

Premise

I'm writing Qiita for the first time, so I'd be happy if you could tell me if there was something like "It's easier to see if you do this." This time, I haven't touched the lines and animation at all.

Conclusion

This is an application that Pepper measures the loudness of the sound when other performers who hear the presenter's presentation applaud and "select the team with the loudest applause".

API used

ALAudioDevice

Method used

getFrontMicEnergy()

Preparation

  1. Name of the target team
  2. Score for each team

For the time being, I made it a global variable.

init.py


    global members
    global scores

    members = ["Pillow", "My Pepper Life Izu Smile", "stopper"]
    scores = [0, 0, 0]

How it works

It's like measuring the loudness at regular intervals and storing the loudest value in the global variable scores.

max_SoundCk.py


    def onLoad(self):
        self.timer = None
        self.limit = 0
        self.audio = ALProxy("ALAudioDevice")

    def onUnload(self):
        self.cancelTimer()
        self.audio.disableEnergyComputation()

    def cancelTimer(self):
        if self.timer:
            self.timer.stop()
        self.timer = None

    def onTimer(self):
        v = self.audio.getFrontMicEnergy()
        if self.maxV < v:
            self.maxV = v
        self.limit += int(self.getParameter("Check Interval (s)") * 1000 * 1000)
        if self.limit >= int(self.getParameter("Limit Measure (s)") * 1000 * 1000):
            self.onInput_onStop()

    def startTimer(self):
        import qi
        self.timer = qi.PeriodicTask()
        self.timer.setCallback(self.onTimer)
        self.timer.setUsPeriod(int(self.getParameter("Check Interval (s)") * 1000 * 1000))
        self.timer.start(True)

    def onInput_onStart(self):
        global members
        global current_member

        self.logger.info("Monitoring start team:%s" % members[current_member])
        self.audio.enableEnergyComputation()
        self.maxV = 0
        self.cancelTimer()
        self.startTimer()

    def onInput_onStop(self):
        global scores
        global current_member

        if self.timer and self.timer.isRunning():
            self.logger.info(self.maxV)
            self.onStopped()
            scores[current_member] = self.maxV

        self.onUnload()

Result announcement

Simply pick out the largest value in scores and announce it.

Say_Text.py


    def onInput_onStart(self):
        global members
        global current_member
        global scores
        
        self.logger.info(members)
        m = 0
        mv = 0
        l = len(members)
        for i in range(0,l)  :
            if scores[i] > mv:
                self.logger.info("%d : %d" % (int(i), int(scores[i])))
                m = i
                mv = scores[i]

        p =  members[m]

        self.bIsRunning = True
        try:
            sentence = "\RSPD="+ str( self.getParameter("Speed (%)") ) + "\ "
            sentence += "\VCT="+ str( self.getParameter("Voice shaping (%)") ) + "\ "
            sentence += str(p)
            sentence +=  "\RST\ "
            id = self.tts.post.say(str(sentence))
            self.ids.append(id)
            self.tts.wait(id, 0)
        finally:
            try:
                self.ids.remove(id)
            except:
                pass
            if( self.ids == [] ):
                self.onStopped() # activate output of the box
                self.bIsRunning = False

sample

This time, I received the source code from ** Master Kawada ** and uploaded a little organized version to Robot Start's Robot Library. So please take a look. https://pepper.robo-lib.com/repositories/summary/41

Recommended Posts

Pepper decides the winner by measuring the size of the audience's applause
Increase the UI size of MyPaint
About the size of matplotlib points
Let's decide the winner of bingo
[pyqtgraph] Set the size ratio of the graph
Align the size of the colorbar with matplotlib
Pandas of the beginner, by the beginner, for the beginner [Python]
Tips: Comparison of the size of three values