wiki:en/ProgrammingRobotsCourse/PepperApi

Version 4 (modified by Ales Horak, 4 months ago) (diff)

--

PV277 Programming Applications for Social Robots (autumn 2019)

Pepper API

  • http://doc.aldebaran.com/2-5/index_dev_guide.html
  • programming in Choregraphe via Python:
    • enter only one box Python Script
    • edit its contents via double click:
      • to __init__ add:
        self.tts = ALProxy('ALTextToSpeech')
        self.tts.setLanguage('Czech')
        
      • to onInput_onStart add:
        self.tts.say("Ahoj, jak se máš?")
        self.onStopped()
        
    • add Czech into Project Properties
    • save the project and run in on a virtual robot
  • speech input via Python:
    • in __init__ add:
          try:
              self.speech = ALProxy("ALSpeechRecognition")
              self.speech.setLanguage('Czech')
          except:
              self.logger.info('Running on virtual robot')
              self.speech = None
      
    • process speech accordingly
      def get_answer(self, reactions):
          if self.speech is None:
              return (random.choice(reactions.keys()))
          else:
              self.speech.setVocabulary(reactions.keys(), False)
              self.speech.subscribe("Test_ASR")
              self.logger.info('Speech recognition engine started')
              time.sleep(20)
              self.speech.unsubscribe("Test_ASR")
      
      def onInput_onStart(self):
          self.tts.say("Ahoj, jak se máš?")
          reactions = {
              'dobře':  'to je super!',
              'špatně': 'doufám, že to brzo bude lepší',
              'nevím': 'tak to určitě nebude tak zlé',
          }
          answer = self.get_answer(reactions)
          react = reactions.get(answer)
          self.logger.info('answer={}, react={}'.format(answer, react))
          self.tts.say(react)
          self.onStopped()
      

Attachments (1)

Download all attachments as: .zip