def startAudioRecording(self, fileName): """Starts recording audio. Args: fileName -- file to use to save stored audio """ droid.makeToast("Starting audio recording") droid.recorderStartMicrophone(fileName)
def specialToast(self, droid, msg): try: # Don't toast the same message repeatedly unless 5 seconds have passed if msg != self.previousToastMsg or \ (time.time() > self.lastToastMsgTime + 5000): droid.makeToast(msg) except: pass self.previousToastMsg=msg self.lastToastMsgTime = time.time()
def speak(self, speech, override=False): """Outputs talk. Args: speech -- string of characters for android speech override -- set to true to override the audioOn state """ # TODO: Move the muted state (audioOn) out of the config object. if (self.config.audioOn and speech != self.previousMsg) or override: droid.ttsSpeak(speech) elif speech != self.previousMsg: droid.makeToast(speech) self.previousMsg = speech
def uplinkFactory(config): """Consult the configuration to determine which uplink to instantiate, and return it Args: config -- global configuration object Returns: uplink -- configured uplink instance required to talk to the cloud """ if config.inputMethod == "commandByJSON": print "Initiating input by JSON" droid.makeToast("Initiating input by JSON") uplink = commandByJSON(config.msgRelayUrl) elif config.inputMethod == "commandByXMPP": print "Initiating input by XMPP" droid.makeToast("Initiating input by XMPP") if config.mode == config.kModeRobot: uplink = commandByXMPP(config.xmppServer, config.xmppPort, config.xmppRobotUsername, config.xmppRobotPassword, None) elif config.mode == config.kModeRemote: uplink = commandByXMPP(config.xmppServer, config.xmppPort, config.xmppRemoteUsername, config.xmppRemoteUserPassword, config.xmppRobotUsername) elif config.inputMethod == "commandByTelnet": print "Initiating input by telnet" droid.makeToast("Initiating input by telnet") if config.mode == config.kModeRemote: phoneIP = config.robotHost else: phoneIP = config.phoneIP uplink = commandByTelnet(phoneIP, config.telnetPort, config.mode == config.kModeRobot) elif config.inputMethod == "commandByVoice": print "Initiating input by voice" droid.makeToast("Initiating input by voice") uplink = commandByVoice() elif (config.inputMethod == "commandBySelf"): print "Initiating input by self remote" droid.makeToast("Initiating input by self remote") uplink = commandBySelf() else: raise UplinkError("Uplink type unrecognized: '%s'" % config.inputMethod) return uplink
def uplinkFactory(config): """Consult the configuration to determine which uplink to instantiate, and return it Args: config -- global configuration object Returns: uplink -- configured uplink instance required to talk to the cloud """ if config.inputMethod == "commandByJSON": print "Initiating input by JSON" droid.makeToast("Initiating input by JSON") uplink = commandByJSON(config.msgRelayUrl) elif config.inputMethod == "commandByXMPP": print "Initiating input by XMPP" droid.makeToast("Initiating input by XMPP") if config.mode == config.kModeRobot: uplink = commandByXMPP( config.xmppServer, config.xmppPort, config.xmppRobotUsername, config.xmppRobotPassword, None) elif config.mode == config.kModeRemote: uplink = commandByXMPP( config.xmppServer, config.xmppPort, config.xmppRemoteUsername, config.xmppRemoteUserPassword, config.xmppRobotUsername) elif config.inputMethod == "commandByTelnet": print "Initiating input by telnet" droid.makeToast("Initiating input by telnet") if config.mode == config.kModeRemote: phoneIP = config.robotHost else: phoneIP = config.phoneIP uplink = commandByTelnet(phoneIP, config.telnetPort, config.mode == config.kModeRobot) elif config.inputMethod == "commandByVoice": print "Initiating input by voice" droid.makeToast("Initiating input by voice") uplink = commandByVoice() elif (config.inputMethod =="commandBySelf"): print "Initiating input by self remote" droid.makeToast("Initiating input by self remote") uplink = commandBySelf() else: raise UplinkError("Uplink type unrecognized: '%s'" % config.inputMethod) return uplink
def recognizeSpeech(self): """Launch the android cloud voice recognition framework and return the result.""" droid.makeToast("Launching voice recognition") return str(droid.recognizeSpeech().result)
def stopAudioRecording(self): """Stops recording audio.""" droid.makeToast("Stopping audio recording") droid.recorderStop()