more documentation
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
#! /usr/bin/env python
|
||||
"""A module for speech detection.
|
||||
|
||||
ROS Node: `speech_server`
|
||||
Provides `request_speech` action
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
import rospy
|
||||
@@ -13,6 +19,7 @@ almem = None
|
||||
|
||||
|
||||
def request_speech(goal):
|
||||
"""Handle the request for speech detection."""
|
||||
rospy.loginfo('SPEECH SERVER: NEW GOAL: {}'.format(goal))
|
||||
if not speech_detector.start_speech(goal.vocabulary):
|
||||
sas.set_succeeded(RequestSpeechResult(word=''))
|
||||
@@ -33,6 +40,7 @@ def request_speech(goal):
|
||||
|
||||
|
||||
class SpeechDetectorModule(ALModule):
|
||||
"""ALModule for accessing the NAO's speech recognition."""
|
||||
|
||||
def __init__(self, name):
|
||||
ALModule.__init__(self, name)
|
||||
@@ -52,6 +60,7 @@ class SpeechDetectorModule(ALModule):
|
||||
return almem.getData('ALSpeechRecognition/Status')
|
||||
|
||||
def start_speech(self, voc, resume=False):
|
||||
"""Start recognizing the given vocabulary."""
|
||||
if self._busy != resume:
|
||||
return False
|
||||
if not resume:
|
||||
@@ -63,14 +72,17 @@ class SpeechDetectorModule(ALModule):
|
||||
return True
|
||||
|
||||
def have_word(self):
|
||||
"""Check if something was recognized."""
|
||||
return self.recognized is not None
|
||||
|
||||
def get_recognized_and_erase(self):
|
||||
"""Retrieve the recognized word and erase it from the variable."""
|
||||
result = self.recognized
|
||||
self.recognized = None
|
||||
return result
|
||||
|
||||
def stop_speech(self, pause=False):
|
||||
"""Stop detecting or just pause detection."""
|
||||
if not self._busy:
|
||||
return
|
||||
self.asr.pause(True)
|
||||
@@ -79,6 +91,7 @@ class SpeechDetectorModule(ALModule):
|
||||
self._busy = False
|
||||
|
||||
def on_word_recognized(self, *_args):
|
||||
"""Callback for word recognized event."""
|
||||
word, conf = almem.getData('WordRecognized')
|
||||
if conf > 0.4:
|
||||
self.stop_speech(pause=True)
|
||||
|
||||
Reference in New Issue
Block a user