예제 #1
0
class ALSpeechRecognition(object):
    def __init__(self):
        self.proxy = None

    def force_connect(self):
        self.proxy = ALProxy("ALSpeechRecognition")

    def activateAllRules(self, contextName):
        """Activate all rules contained in the specified context.

        :param str contextName: Name of the context to modify.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.activateAllRules(contextName)

    def activateRule(self, contextName, ruleName):
        """Activate a rule contained in the specified context.

        :param str contextName: Name of the context to modify.
        :param str ruleName: Name of the rule to activate.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.activateRule(contextName, ruleName)

    def addContext(self, pathToLCFFile, contextName):
        """Add a context from a LCF file.

        :param str pathToLCFFile: Path to a LCF file. This LCF file contains the set of rules that should be recognized by the speech recognition engine.
        :param str contextName: Name of the context of your choice.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.addContext(pathToLCFFile, contextName)

    def addWordListToSlot(self, contextName, slotName, wordList):
        """Add a list of words in a slot. A slot is a part of a context which can be modified. You can add a list of words that should be recognized by the speech recognition engine

        :param str contextName: Name of the context to modify.
        :param str slotName: Name of the slot to modify.
        :param std::vector<std::string> wordList: List of words to insert in the slot.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.addWordListToSlot(contextName, slotName, wordList)

    def compile(self, arg1, arg2, arg3):
        """

        :param str arg1: arg
        :param str arg2: arg
        :param str arg3: arg
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.compile(arg1, arg2, arg3)

    def deactivateAllRules(self, contextName):
        """Deactivate all rules contained in the specified context.

        :param str contextName: Name of the context to modify.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.deactivateAllRules(contextName)

    def deactivateRule(self, contextName, ruleName):
        """Deactivate a rule contained in the specified context.

        :param str contextName: Name of the context to modify.
        :param str ruleName: Name of the rule to deactivate.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.deactivateRule(contextName, ruleName)

    def eraseContextSet(self, saveName):
        """Erase a saved context set of the speech recognition engine

        :param str saveName: Name under which the context set is saved
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.eraseContextSet(saveName)

    def getAudioExpression(self):
        """To check if audio expression is enabled or disabled.

        :returns bool: 
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getAudioExpression()

    def getAvailableLanguages(self):
        """Returns the list of the languages installed on the system.

        :returns std::vector<std::string>: Array of strings that contains the list of the installed languages.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getAvailableLanguages()

    def getContextParam(self, contextName, paramName):
        """Get the given parameter for the specified context.

        :param str contextName: Name of the context
        :param str paramName: Name of the parameter to get
        :returns float: Value of the fetched parameter
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getContextParam(contextName, paramName)

    def getCurrentPeriod(self):
        """Gets the current period.

        :returns int: Refresh period (in milliseconds).
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getCurrentPeriod()

    def getCurrentPrecision(self):
        """Gets the current precision.

        :returns float: Precision of the extractor.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getCurrentPrecision()

    def getEventList(self):
        """Get the list of events updated in ALMemory.

        :returns std::vector<std::string>: Array of events updated by this extractor in ALMemory
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getEventList()

    def getLanguage(self):
        """Returns the current language used by the speech recognition system.

        :returns str: Current language used by the speech recognition engine.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getLanguage()

    def getMemoryKeyList(self):
        """Get the list of events updated in ALMemory.

        :returns std::vector<std::string>: Array of events updated by this extractor in ALMemory
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getMemoryKeyList()

    def getMyPeriod(self, name):
        """Gets the period for a specific subscription.

        :param str name: Name of the module which has subscribed.
        :returns int: Refresh period (in milliseconds).
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getMyPeriod(name)

    def getMyPrecision(self, name):
        """Gets the precision for a specific subscription.

        :param str name: name of the module which has subscribed
        :returns float: precision of the extractor
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getMyPrecision(name)

    def getOutputNames(self):
        """Get the list of values updated in ALMemory.

        :returns std::vector<std::string>: Array of values updated by this extractor in ALMemory
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getOutputNames()

    def getParameter(self, paramName):
        """Gets a parameter of the speech recognition engine. Note that when the ASR engine language is set to Chinese, no parameter can be retrieved

        :param str paramName: Name of the parameter.
        :returns float: Value of the parameter.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getParameter(paramName)

    def getRules(self, contextName, typeName):
        """Get all rules contained for a specific context.

        :param str contextName: Name of the context to analyze.
        :param str typeName: Type of the required rules.
        :returns std::vector<std::string>: 
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getRules(contextName, typeName)

    def getSubscribersInfo(self):
        """Gets the parameters given by the module.

        :returns AL::ALValue: Array of names and parameters of all subscribers.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.getSubscribersInfo()

    def loadContextSet(self, saveName):
        """Load a saved context set of the speech recognition engine

        :param str saveName: Name under which the context set is saved
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.loadContextSet(saveName)

    def loadVocabulary(self, vocabularyFile):
        """Loads the vocabulary to recognized contained in a .lxd file. This method is not available with the ASR engine language set to Chinese. For more informations see the red documentation

        :param str vocabularyFile: Name of the lxd file containing the vocabulary
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.loadVocabulary(vocabularyFile)

    def pause(self, pause):
        """Stops and restarts the speech recognition engine according to the input parameter This can be used to add contexts, activate or deactivate rules of a contex, add a words to a slot.

        :param bool pause: Boolean to enable or disable pause of the speech recognition engine.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.pause(pause)

    def ping(self):
        """Just a ping. Always returns true

        :returns bool: returns true
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.ping()

    def popContexts(self):
        """Disable current contexts and restore saved contexts of the speech recognition engine.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.popContexts()

    def pushContexts(self):
        """Disable current contexts of the speech recognition engine and save them in a  stack.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.pushContexts()

    def removeAllContext(self):
        """Remove all contexts from the speech recognition engine.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.removeAllContext()

    def removeContext(self, contextName):
        """Remove one context from the speech recognition engine.

        :param str contextName: Name of the context to remove from the speech recognition engine.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.removeContext(contextName)

    def removeWordListFromSlot(self, contextName, slotName):
        """Remove all words from a slot.

        :param str contextName: Name of the context to modify.
        :param str slotName: Name of the slot to modify.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.removeWordListFromSlot(contextName, slotName)

    def saveContextSet(self, saveName):
        """Save current context set of the speech recognition engine

        :param str saveName: Name under which to save
        :returns bool: 
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.saveContextSet(saveName)

    def setAudioExpression(self, setOrNot):
        """Enables or disables the playing of sounds indicating the state of the recognition engine. If this option is enabled, a sound is played at the beginning of the recognition process (after a call to the subscribe method), and a sound is played when the user call the unsubscribe method

        :param bool setOrNot: Enable (true) or disable it (false).
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setAudioExpression(setOrNot)

    def setContextParam(self, contextName, paramName, value):
        """Set the given parameter for the specified context.

        :param str contextName: Name of the context
        :param str paramName: Name of the parameter to change
        :param float value: New parameter value
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setContextParam(contextName, paramName, value)

    def setLanguage(self, languageName):
        """Sets the language used by the speech recognition engine. The list of the available languages can be collected through the getAvailableLanguages method. If you want to set a language as the default language (loading automatically at module launch), please refer to the web page of the robot.

        :param str languageName: Name of the language in English.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setLanguage(languageName)

    def setParameter(self, paramName, paramValue):
        """Sets a parameter of the speech recognition engine. Note that when the ASR engine language is set to Chinese, no parameter can be set. The parameters that can be set and the corresponding values are: "Sensitivity" - Values : range is [0.0; 1.0]. "Timeout" - Values :  default values 3000 ms. Timeout for the remote recognition "MinimumTrailingSilence" : Values : 0 (no) or 1 (yes) - Applies a High-Pass filter on the input signal - default value is 0.

        :param str paramName: Name of the parameter.
        :param float paramValue: Value of the parameter.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setParameter(paramName, paramValue)

    def setParameter2(self, paramName, paramValue):
        """Sets a parameter of the speech recognition engine. Note that when the ASR engine language is set to Chinese, no parameter can be set. The parameters that can be set and the corresponding values are: "Sensitivity" - Values : range is [0.0; 1.0]. "Timeout" - Values :  default values 3000 ms. Timeout for the remote recognition "MinimumTrailingSilence" : Values : 0 (no) or 1 (yes) - Applies a High-Pass filter on the input signal - default value is 0.

        :param str paramName: Name of the parameter.
        :param bool paramValue: Value of the parameter.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setParameter(paramName, paramValue)

    def setVisualExpression(self, setOrNot):
        """Enables or disables the leds animations showing the state of the recognition engine during the recognition process.

        :param bool setOrNot: Enable (true) or disable it (false).
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setVisualExpression(setOrNot)

    def setVisualExpressionMode(self, mode):
        """Sets the LED animation mode

        :param int mode: animation mode: 0: deactivated, 1: eyes, 2: ears, 3: full
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setVisualExpressionMode(mode)

    def setVocabulary(self, vocabulary, enabledWordSpotting):
        """Sets the list of words (vocabulary) that should be recognized by the speech recognition engine.

        :param std::vector<std::string> vocabulary: List of words that should be recognized
        :param bool enabledWordSpotting: If disabled, the engine expects to hear one of the specified words, nothing more, nothing less. If enabled, the specified words can be pronounced in the middle of a whole speech stream, the engine will try to spot them.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setVocabulary(vocabulary, enabledWordSpotting)

    def setWordListAsVocabulary(self, vocabulary):
        """Sets the list of words (vocabulary) that should be recognized by the speech recognition engine.

        :param std::vector<std::string> vocabulary: List of words that should be recognized
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.setWordListAsVocabulary(vocabulary)

    def subscribe(self, name, period, precision):
        """Subscribes to the extractor. This causes the extractor to start writing information to memory using the keys described by getOutputNames(). These can be accessed in memory using ALMemory.getData("keyName"). In many cases you can avoid calling subscribe on the extractor by just calling ALMemory.subscribeToEvent() supplying a callback method. This will automatically subscribe to the extractor for you.

        :param str name: Name of the module which subscribes.
        :param int period: Refresh period (in milliseconds) if relevant.
        :param float precision: Precision of the extractor if relevant.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.subscribe(name, period, precision)

    def subscribe2(self, name):
        """Subscribes to the extractor. This causes the extractor to start writing information to memory using the keys described by getOutputNames(). These can be accessed in memory using ALMemory.getData("keyName"). In many cases you can avoid calling subscribe on the extractor by just calling ALMemory.subscribeToEvent() supplying a callback method. This will automatically subscribe to the extractor for you.

        :param str name: Name of the module which subscribes.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.subscribe(name)

    def unsubscribe(self, name):
        """Unsubscribes from the extractor.

        :param str name: Name of the module which had subscribed.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.unsubscribe(name)

    def updatePeriod(self, name, period):
        """Updates the period if relevant.

        :param str name: Name of the module which has subscribed.
        :param int period: Refresh period (in milliseconds).
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.updatePeriod(name, period)

    def updatePrecision(self, name, precision):
        """Updates the precision if relevant.

        :param str name: Name of the module which has subscribed.
        :param float precision: Precision of the extractor.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.updatePrecision(name, precision)

    def version(self):
        """Returns the version of the module.

        :returns str: A string containing the version of the module.
        """
        if not self.proxy:
            self.proxy = ALProxy("ALSpeechRecognition")
        return self.proxy.version()