Changes between Version 34 and Version 35 of en/ProgrammingRobotsCourse/PepperApi


Ignore:
Timestamp:
Feb 16, 2022, 3:12:26 PM (2 years ago)
Author:
Ales Horak
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • en/ProgrammingRobotsCourse/PepperApi

    v34 v35  
    1212  * enter only one box `Python Script`
    1313  * edit its contents via double click:
    14     * to `__init__` add:
     14    * to `onLoad` add:
    1515      {{{#!python
    1616self.tts = ALProxy('ALTextToSpeech')
     
    2828
    2929=== speech input via Python
    30   * in `__init__` add:
     30  * in `odLoad` add:
    3131    {{{#!python
     32        self.dialog = ALProxy('ALDialog')
     33        self.dialog.setLanguage('Czech')
     34        self.mem = ALProxy('ALMemory')
    3235        try:
    3336            self.speech = ALProxy("ALSpeechRecognition")
    3437            self.speech.setLanguage('Czech')
     38            self.logger.info('Running on real robot')
    3539        except:
    3640            self.logger.info('Running on virtual robot')
     
    4145    def get_answer(self, reactions):
    4246        if self.speech is None:
     47            # random answer on virtual robot
    4348            return (random.choice(reactions.keys()))
    4449        else:
    45             self.speech.setVocabulary(reactions.keys(), False)
     50            try:
     51                self.speech.setVocabulary(reactions.keys(), False)
     52            except RuntimeError: # fix incorrectly reset dialog
     53                self.logger.info('Reset language')
     54                self.dialog.setLanguage('English')
     55                self.onLoad()
     56                self.speech.setVocabulary(reactions.keys(), False)
    4657            self.speech.subscribe("Test_ASR")
    4758            self.logger.info('Speech recognition engine started')
    48             time.sleep(20)
     59            while True:
     60                word = self.mem.getData("WordRecognized")
     61                if type(word) == list and word[0] != '':
     62                    break
    4963            self.speech.unsubscribe("Test_ASR")
     64            return word[0]
    5065
    5166    def onInput_onStart(self):
     
    6277        self.onStopped()
    6378}}}
    64   * in case of error `ALSpeechRecognition::setVocabulary                NuanceContext::addContext       A grammar named "modifiable_grammar" already exists` just rerun the app once more.
     79  * in case of error `ALSpeechRecognition::setVocabulary                NuanceContext::addContext       A grammar named "modifiable_grammar" already exists` just rerun the app once more. But this should be already solved by the included "''fix incorrectly reset dialog''".
    6580  * see [http://doc.aldebaran.com/2-5/naoqi/audio/alspeechrecognition.html ALSpeechRecognition] documentation
    6681