| 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 | |