Changes between Version 3 and Version 4 of en/ProgrammingRobotsCourse/PepperApi


Ignore:
Timestamp:
Sep 30, 2019, 4:55:03 PM (5 years ago)
Author:
Ales Horak
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • en/ProgrammingRobotsCourse/PepperApi

    v3 v4  
    88  * edit its contents via double click:
    99    * to `__init__` add:
    10       {{{
     10      {{{#!python
    1111self.tts = ALProxy('ALTextToSpeech')
    1212self.tts.setLanguage('Czech')
    1313}}}
    1414    * to `onInput_onStart` add:
    15       {{{
     15      {{{#!python
    1616self.tts.say("Ahoj, jak se máš?")
    1717self.onStopped()
     
    1919   * add `Czech` into Project Properties [[br]]
    2020     [[Image(pepper_project_cz.png)]]
     21   * save the project and run in on a virtual robot
     22* speech input via Python:
     23  * in `__init__` add:
     24    {{{#!python
     25        try:
     26            self.speech = ALProxy("ALSpeechRecognition")
     27            self.speech.setLanguage('Czech')
     28        except:
     29            self.logger.info('Running on virtual robot')
     30            self.speech = None
     31}}}
     32  * process speech accordingly
     33    {{{#!python
     34    def get_answer(self, reactions):
     35        if self.speech is None:
     36            return (random.choice(reactions.keys()))
     37        else:
     38            self.speech.setVocabulary(reactions.keys(), False)
     39            self.speech.subscribe("Test_ASR")
     40            self.logger.info('Speech recognition engine started')
     41            time.sleep(20)
     42            self.speech.unsubscribe("Test_ASR")
     43
     44    def onInput_onStart(self):
     45        self.tts.say("Ahoj, jak se máš?")
     46        reactions = {
     47            'dobře':  'to je super!',
     48            'špatně': 'doufám, že to brzo bude lepší',
     49            'nevím': 'tak to určitě nebude tak zlé',
     50        }
     51        answer = self.get_answer(reactions)
     52        react = reactions.get(answer)
     53        self.logger.info('answer={}, react={}'.format(answer, react))
     54        self.tts.say(react)
     55        self.onStopped()
     56}}}
     57
     58