def webSearchConfirmation(self, speech, language, regMatched): webSearchQuery = regMatched.group(1) #webSearchConfirmation = regMatched.group(2) lang = language.split("-")[0] resultCallback1View = UIAddViews(refId="") resultCallback1ViewView = UIAssistantUtteranceView() resultCallback1ViewView.dialogIdentifier="WebSearch#initiateWebSearch" resultCallback1ViewView.text=webSearchAnswerText[lang].format(u"„{0}“".format(webSearchQuery)) resultCallback1ViewView.speakableText=webSearchAnswerText[lang].format(webSearchQuery) resultCallback1View.views = [resultCallback1ViewView] search = WebSearch(refId="", aceId="", query=webSearchQuery) resultCallback3View = UIAddViews(refId="") resultCallback3ViewView = UIAssistantUtteranceView() resultCallback3ViewView.dialogIdentifier="WebSearch#fatalResponse" resultCallback3ViewView.text=webSearchAnswerFailureText[lang] resultCallback3ViewView.speakableText=webSearchAnswerFailureText[lang] resultCallback3View.views=[resultCallback3ViewView] resultCallback3 = ResultCallback(commands=[resultCallback3View]) search.callbacks = [resultCallback3] resultCallback2 = ResultCallback(commands=[search]) resultCallback1View.callbacks = [resultCallback2] self.complete_request(callbacks=[ResultCallback(commands=[resultCallback1View])])
def call(self, phone, person, language): if phone == None: print "abandon" self.complete_request() return root = ResultCallback(commands=[]) rootView = AddViews("", temporary=False, dialogPhase="Completion", views=[]) root.commands.append(rootView) rootView.views.append( AssistantUtteranceView( text=responses['callPerson'][language].format( person.fullName, numberTypesLocalized[phone.label][language], phone.number), speakableText=responses['callPersonSpeak'][language].format( person.fullName, numberTypesLocalized[phone.label][language]), dialogIdentifier="PhoneCall#initiatePhoneCall", listenAfterSpeaking=False)) rootView.callbacks = [] # create some infos of the target personAttribute = PersonAttribute(data=phone.number, displayText=person.fullName, obj=Person()) personAttribute.object.identifer = person.identifier call = PhoneCall("", recipient=phone.number, faceTime=False, callRecipient=personAttribute) rootView.callbacks.append(ResultCallback(commands=[call])) call.callbacks = [] # now fill in error messages (airplanemode, no service, invalidNumber, fatal) for i in range(4): errorRoot = AddViews(None, temporary=False, dialogPhase="Completion", scrollToTop=False, views=[]) errorRoot.views.append( AssistantUtteranceView( text=errorOnCallResponse[language][i]['text'], speakableText=errorOnCallResponse[language][i]['text'], dialogIdentifier=errorOnCallResponse[language][i] ['dialogIdentifier'], listenAfterSpeaking=False)) call.callbacks.append( ResultCallback(commands=[errorRoot], code=errorOnCallResponse[language][i]['code'])) self.complete_request([root])
def play(self, results, language): collection = MPTitleCollection() collection.items = [] for result in results: if not hasattr(result, 'genre'): result.genre = "" if not hasattr(result, 'trackNumber'): result.trackNumber = "" if not hasattr(result, 'artist'): result.artist = "" if not hasattr(result, 'title'): result.title = "" if not hasattr(result, 'sortTitle'): result.sortTitle = "" if not hasattr(result, 'playCount'): result.playCount = "" if not hasattr(result, 'rating'): result.rating = "" if not hasattr(result, 'album'): result.album = "" if not hasattr(result, 'identifier'): result.identifier = "" song = MPSong() song.album = result.album song.artist = result.artist song.genre = result.genre song.playCount = result.playCount song.rating = result.rating song.sortTitle = result.sortTitle song.title = result.title song.trackNumber = result.trackNumber song.identifier = result.identifier collection.items.append(song) collection.sortTitle = result.title collection.title = result.sortTitle collection.identifier = result.identifier complete = MPSetQueue(self.refId) complete.mediaItems = collection self.getResponseForRequest(complete) commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPEnableShuffle(self.refId) commands2.enable = False code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#nowPlayingMediaItemByTitle" assistant.speakableText = assistant.text = res["play"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def resume(self, language): commands = MPSetState(self.refId) commands.state = "Playing" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#SkipToNext" assistant.speakableText = assistant.text = res["resume"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def back(self, language): commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPSetPlaybackPosition(self.refId) commands2.position = "PreviousItem" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#Previous" assistant.speakableText = assistant.text = res["back"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def webSearchConfirmation(self, speech, language): # lets use a little hack to get that regex matcher = self.webSearchConfirmation.__dict__[__criteria_key__]['de-DE'] regMatched = matcher.match(speech) webSearchQuery = regMatched.group(1) webSearchConfirmation = regMatched.group(2) lang = language.split("-")[0] resultCallback1View = AddViews(refId="", views=[AssistantUtteranceView(dialogIdentifier="WebSearch#initiateWebSearch", text=webSearchAnswerText[lang].format(u"„{0}“".format(webSearchQuery)), speakableText=webSearchAnswerText[lang].format(webSearchQuery))]) search = WebSearch(refId="", aceId="", query=webSearchQuery) resultCallback3View = AddViews(refId="", views=[AssistantUtteranceView(dialogIdentifier="WebSearch#fatalResponse", text=webSearchAnswerFailureText[lang], speakableText=webSearchAnswerFailureText[lang])]) resultCallback3 = ResultCallback(commands=[resultCallback3View]) search.callbacks = [resultCallback3] resultCallback2 = ResultCallback(commands=[search]) resultCallback1View.callbacks = [resultCallback2] self.complete_request(callbacks=[ResultCallback(commands=[resultCallback1View])])