コード例 #1
0
ファイル: __init__.py プロジェクト: HengeSense/SiriServerCore
 def findPhoneForNumberType(self, person, numberType, language):         
     # first check if a specific number was already requested
     phoneToMessage = None
     if numberType != None:
         # try to find the phone that fits the numberType
         listToMessage = filter(lambda x: x.label == numberType, person.phones)
         if len(listToMessage) == 1:
             phoneToMessage = listToMessage[0]
     else:
         favPhones = filter(lambda y: y.favoriteVoice if hasattr(y, "favoriteVoice") else False, person.phones)
         if len(favPhones) == 1:
             phoneToMessage = favPhones[0]
     if phoneToMessage == None:
         # lets check if there is more than one number
         if len(person.phones) == 1:
             if numberType != None:
                 self.say(errorNumberNotPresent.format(numberTypesLocalized[numberType][language], person.fullName))
             phoneToMessage = person.phones[0]
         else:
             # damn we need to ask the user which one he wants...
             if phoneToMessage == None:
                 root = UIAddViews(self.refId)
                 root.dialogPhase = root.DialogPhaseClarificationValue
                 
                 utterance = UIAssistantUtteranceView()
                 utterance.dialogIdentifier = "ContactDataResolutionDucs#foundAmbiguousPhoneNumberForContact"
                 utterance.speakableText = utterance.text = responses['selectNumber'][language].format(person.fullName)
                 utterance.listenAfterSpeaking = True
                 
                 root.views = [utterance]
                 
                 lst = UIDisambiguationList()
                 lst.items = []
                 lst.speakableSelectionResponse = ""
                 lst.listenAfterSpeaking = True
                 lst.selectionResponse = ""
                 root.views.append(lst)
                 for phone in person.phones:
                     numberType = numberTypesLocalized[phone.label][language] if phone.label in numberTypesLocalized else phone.label
                     item = UIListItem()
                     item.title = ""
                     item.text = u"{0}: {1}".format(numberType, phone.number)
                     item.selectionText = item.text
                     item.speakableText = u"{0}, ".format(numberType)
                     item.object = phone
                     item.commands = [SendCommands(commands=[StartRequest(handsFree=False, utterance=numberType)])]
                     lst.items.append(item)
                     
                 answer = self.getResponseForRequest(root)
                 numberType = self.getNumberTypeForName(answer, language)
                 if numberType != None:
                     matches = filter(lambda x: x.label == numberType, person.phones)
                     if len(matches) == 1:
                         phoneToMessage = matches[0]
                     else:
                         self.say(errorNumberTypes[language])
                 else:
                     self.say(errorNumberTypes[language])
     return phoneToMessage
コード例 #2
0
ファイル: __init__.py プロジェクト: imclab/SiriServerPlugins
    def findPhoneForNumberType(self, person, numberType, language):
        # first check if a specific number was already requested
        phoneToMessage = None
        if numberType != None:
            # try to find the phone that fits the numberType
            phoneToMessage = filter(lambda x: x.label == numberType,
                                    person.phones)
        else:
            favPhones = filter(
                lambda y: y.favoriteVoice
                if hasattr(y, "favoriteVoice") else False, person.phones)
            if len(favPhones) == 1:
                phoneToMessage = favPhones[0]
        if phoneToMessage == None:
            # lets check if there is more than one number
            if len(person.phones) == 1:
                if numberType != None:
                    self.say(
                        errorNumberNotPresent.format(
                            numberTypesLocalized[numberType][language],
                            person.fullName))
                phoneToMessage = person.phones[0]
            else:
                # damn we need to ask the user which one he wants...
                while (phoneToMessage == None):
                    root = UIAddViews(self.refId)
                    root.dialogPhase = root.DialogPhaseClarificationValue

                    utterance = UIAssistantUtteranceView()
                    utterance.dialogIdentifier = "ContactDataResolutionDucs#foundAmbiguousPhoneNumberForContact"
                    utterance.speakableText = utterance.text = responses[
                        'selectNumber'][language].format(person.fullName)
                    utterance.listenAfterSpeaking = True

                    root.views = [utterance]

                    lst = UIDisambiguationList()
                    lst.items = []
                    lst.speakableSelectionResponse = "OK!"
                    lst.listenAfterSpeaking = True
                    lst.selectionResponse = "OK"
                    root.views.append(lst)
                    for phone in person.phones:
                        numberType = numberTypesLocalized[phone.label][
                            language] if phone.label in numberTypesLocalized else phone.label
                        item = UIListItem()
                        item.title = ""
                        item.text = u"{0}: {1}".format(numberType,
                                                       phone.number)
                        item.selectionText = item.text
                        item.speakableText = u"{0}  ".format(numberType)
                        item.object = phone
                        item.commands = [
                            SendCommands(commands=[
                                StartRequest(handsFree=False,
                                             utterance=numberType)
                            ])
                        ]
                        lst.items.append(item)

                    answer = self.getResponseForRequest(root)
                    numberType = self.getNumberTypeForName(answer, language)
                    if numberType != None:
                        matches = filter(lambda x: x.label == numberType,
                                         person.phones)
                        if len(matches) == 1:
                            phoneToMessage = matches[0]
                        else:
                            self.say(errorNumberTypes[language])
                    else:
                        self.say(errorNumberTypes[language])
        return phoneToMessage