Exemple #1
0
    def ListenForCommand(self):
        L.debug('Listening for a voice command')

        RecognizedCommand = ''
        RecognizedCommand = STT.SpeechToText()

        if RecognizedCommand != '':
            CommandRegExPattern = r'\b%s\b' % Settings.GeneralKnowledgeTriggerPhrase
            CommandRegExResult = re.search(CommandRegExPattern,
                                           RecognizedCommand, re.IGNORECASE)

            SP.PlayAudioFile(FileName='EndBeep.mp3')

            if (CommandRegExResult) and (Settings.UseGeneralKnowledge):
                if Settings.GeneralKnowledgeEngine.lower() == 'apiai':
                    OR.QueryApiAI(RecognizedCommand)
            else:
                VoiceCommandItemURL = ''

                if Settings.Port.strip() != '':
                    TrimmedHostAndPort = Settings.HostName.strip(
                    ) + ':' + Settings.Port.strip()
                else:
                    TrimmedHostAndPort = Settings.HostName.strip()

                if Settings.SSLConnection:
                    URLPrefix = 'https://'
                else:
                    URLPrefix = 'http://'

                VoiceCommandItemURL = URLPrefix + TrimmedHostAndPort + '/CMD?' + Settings.VoiceCommandItem + '=' + '"' + RecognizedCommand + '"'

                if (Settings.Username.strip() !=
                        '') and (Settings.Password.strip() != ''):
                    HTTPGetResult = requests.get(
                        VoiceCommandItemURL,
                        auth=(Settings.Username.strip(),
                              Settings.Password.strip()))
                else:
                    HTTPGetResult = requests.get(VoiceCommandItemURL)
Exemple #2
0
    def ListenForWakeUp(self):
        TTSReady = random.choice(
            open(Settings.FinalizationDataFile).readlines())
        M.ProcessMessage(TTSReady)

        while True:
            L.debug('Listening for a wake-up phrase')

            RecognizedWakeUp = ''
            RecognizedWakeUp = STT.SpeechToText(Settings.UseOfflineWakeUp)

            WakeUpRegExPattern = r'\b%s\b' % Settings.WakeUpPhrase
            WakeUpRegExResult = re.search(WakeUpRegExPattern, RecognizedWakeUp,
                                          re.IGNORECASE)

            if WakeUpRegExResult:
                if Settings.UseTextToSpeech:
                    TTSGreeting = random.choice(
                        open(Settings.GreetingDataFile).readlines())
                    M.ProcessMessage(TTSGreeting)
                else:
                    SP.PlayAudioFile(FileName='StartBeep.mp3')

                self.ListenForCommand()