“Alexa,打开 Mighty Righty” - 有效 /// “Alexa,问 Mighty Righty 谁是对的,我还是我丈夫”不起作用(嗯,我不知道那个)

Posted

技术标签:

【中文标题】“Alexa,打开 Mighty Righty” - 有效 /// “Alexa,问 Mighty Righty 谁是对的,我还是我丈夫”不起作用(嗯,我不知道那个)【英文标题】:"Alexa, open Mighty Righty" - works /// "Alexa, ask Mighty Righty who is right, me or my husband" doesn't work (hmm, I don't know that one) 【发布时间】:2019-10-17 14:12:29 【问题描述】:

我发布的技能可以通过“Alexa,打开 Mighty Righty”来调用,但如果用户说“Alexa,问 Mighty Righty 谁是对的,我还是我的丈夫”,它将不起作用,该怎么做?

https://www.amazon.com/dp/B07SGBR24G/

这是工作已发布技能的链接。

#------------------------------Part1--------------------------------
# In this part we define a list that contains the player names, and 
# a dictionary with player biographies

Player_LIST = ["me or my wife", "me or my husband", "me or you"]

Player_BIOGRAPHY = "me or my wife": ["She is. Do as she says, and you'll be OK.", "You", "Of course, your wife", "No doubt, it's you"],

"me or my husband": ["He is", "You are right", "He is not right", "Your husband. He is always right."],

"me or you": ["me", "You are, ... I mean... you are wrong, of course", "of course me", "It's me, don't you know that, my friend?", "you yourself, what do you think? Of course it's me", "I always know who is right, me or not me, so, it's me", "what do you think? I am Mighty Righty, so I am RIGHT"]

#------------------------------Part2--------------------------------
# Here we define our Lambda function and configure what it does when 
# an event with a Launch, Intent and Session End Requests are sent. # The Lambda function responses to an event carrying a particular 
# Request are handled by functions such as on_launch(event) and 
# intent_scheme(event).

def lambda_handler(event, context):
    if event['session']['new']:
        on_start()
    if event['request']['type'] == "LaunchRequest":
        return on_launch(event)
    elif event['request']['type'] == "IntentRequest":
        return intent_scheme(event)
    elif event['request']['type'] == "SessionEndedRequest":
        return on_end()

#------------------------------Part3--------------------------------
# Here we define the Request handler functions

def on_start():
    print("Session Started.")

def on_launch(event):
    onlunch_MSG = "Hi, start with the word. Me. For example: who is right, me or my husband?"
    reprompt_MSG = "you can say, who is right, me or my wife?"
    card_TEXT = "Who is right, me or... ?."
    card_TITLE = "Choose your question."
    return output_json_builder_with_reprompt_and_card(onlunch_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)

def on_end():
    print("Session Ended.")

#-----------------------------Part3.1-------------------------------
# The intent_scheme(event) function handles the Intent Request. 
# Since we have a few different intents in our skill, we need to 
# configure what this function will do upon receiving a particular 
# intent. This can be done by introducing the functions which handle 
# each of the intents.

def intent_scheme(event):

    intent_name = event['request']['intent']['name']

    if intent_name == "playerBio":
        return player_bio(event)        
    elif intent_name in ["AMAZON.NoIntent", "AMAZON.StopIntent", "AMAZON.CancelIntent"]:
        return stop_the_skill(event)
    elif intent_name == "AMAZON.HelpIntent":
        return assistance(event)
    elif intent_name == "AMAZON.FallbackIntent":
        return fallback_call(event)

#---------------------------Part3.1.1-------------------------------
# Here we define the intent handler functions

import random # this can be at the top of the file too
def player_bio(event):
    name=event['request']['intent']['slots']['player']['value']
    player_list_lower=[w.lower() for w in Player_LIST]
    if name.lower() in player_list_lower:
        reprompt_MSG = "Try to say something like. who is right me or them"
        card_TEXT = "You've picked " + name.lower()
        card_TITLE = "You've picked " + name.lower()
        return output_json_builder_with_reprompt_and_card(random.choice(Player_BIOGRAPHY[name.lower()]), card_TEXT, card_TITLE, reprompt_MSG, False)
    else:
        wrongname_MSG = "Some questions may not yet be present in my database. Try to rephrase your sentence."
        reprompt_MSG = "For example, who is right, me or my wife?"
        card_TEXT = "Use the full question."
        card_TITLE = "Wrong question."
        return output_json_builder_with_reprompt_and_card(wrongname_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)

def stop_the_skill(event):
    stop_MSG = "Bye for now and feel free to ask mighty righty who is right"
    reprompt_MSG = "next time just tell me. Open Mighty righty"
    card_TEXT = "Bye."
    card_TITLE = "Bye Bye."
    return output_json_builder_with_reprompt_and_card(stop_MSG, card_TEXT, card_TITLE, reprompt_MSG, True)

def assistance(event):
    assistance_MSG = "start with the word. Me."
    reprompt_MSG = "For example, who is right me or him"
    card_TEXT = "You've asked for help."
    card_TITLE = "Help"
    return output_json_builder_with_reprompt_and_card(assistance_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)

def fallback_call(event):
    fallback_MSG = "Try to say, for example, who is right, me or him?"
    reprompt_MSG = "Certain answers may not yet be in my database. Use personal pronouns, for example: me, or her, me, or him, me, or them. They can cover pretty much everybody"
    card_TEXT = "You've asked a wrong question."
    card_TITLE = "Wrong question."
    return output_json_builder_with_reprompt_and_card(fallback_MSG, card_TEXT, card_TITLE, reprompt_MSG, False)

#------------------------------Part4--------------------------------
# The response of our Lambda function should be in a json format. 
# That is why in this part of the code we define the functions which 
# will build the response in the requested format. These functions
# are used by both the intent handlers and the request handlers to 
# build the output.

def plain_text_builder(text_body):
    text_dict = 
    text_dict['type'] = 'PlainText'
    text_dict['text'] = text_body
    return text_dict

def reprompt_builder(repr_text):
    reprompt_dict = 
    reprompt_dict['outputSpeech'] = plain_text_builder(repr_text)
    return reprompt_dict

def card_builder(c_text, c_title):
    card_dict = 
    card_dict['type'] = "Simple"
    card_dict['title'] = c_title
    card_dict['content'] = c_text
    return card_dict    

def response_field_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value):
    speech_dict = 
    speech_dict['outputSpeech'] = plain_text_builder(outputSpeach_text)
    speech_dict['card'] = card_builder(card_text, card_title)
    speech_dict['reprompt'] = reprompt_builder(reprompt_text)
    speech_dict['shouldEndSession'] = value
    return speech_dict

def output_json_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value):
    response_dict = 
    response_dict['version'] = '1.0'
    response_dict['response'] = response_field_builder_with_reprompt_and_card(outputSpeach_text, card_text, card_title, reprompt_text, value)
    return response_dict

这是 JSON 文件。可能会略有不同,因为我为了这个问题的目的尽可能地缩短了文件,但这并不重要,因为这里的主要组件 - 存在于当前工作的应用程序中:


    "interactionModel": 
        "languageModel": 
            "invocationName": "mighty righty",
            "intents": [
                
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                ,
                
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                ,
                
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                ,
                
                    "name": "AMAZON.StopIntent",
                    "samples": []
                ,
                
                    "name": "playerBio",
                    "slots": [
                        
                            "name": "player",
                            "type": "playerNames"
                        
                    ],
                    "samples": [
                        "who is right player"
                    ]
                ,
                
                    "name": "AMAZON.NoIntent",
                    "samples": []
                ,
                
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                
            ],
            "types": [
                
                    "name": "playerNames",
                    "values": [
                        
                            "name": 
                                "value": "me or you",
                                "synonyms": [
                                    "you or me"
                                ]
                            
                        ,
                        
                            "name": 
                                "value": "me or them",
                                "synonyms": [
                                    "I am or they are",
                                    "I am or them",
                                    "I am or they",
                                    "I or they are",
                                    "I or them",
                                    "me or they are",
                                    "me or they"
                                ]
                            
                        ,
                        
                            "name": 
                                "value": "me or him",
                                "synonyms": [
                                    "I or him",
                                    "I or he",
                                    "I'm or he is",
                                    "I'm or him",
                                    "me or he is",
                                    "me or he's"
                                ]
                            
                        ,
                        
                            "name": 
                                "value": "me or her",
                                "synonyms": [
                                    "I'm or she's",
                                    "I am or she is",
                                    "I'm or she",
                                    "I'm or her",
                                    "me or she is",
                                    "me or she"
                                ]
                            
                        ,
                        
                            "name": 
                                "value": "me or my wife",
                                "synonyms": [
                                    "me or my wifey"
                                ]
                            
                        ,
                        
                            "name": 
                                "value": "me or my husband",
                                "synonyms": [
                                    "my husband"
                                ]
                            
                        
                    ]
                
            ]
        
    


顺便说一句,您可以看到有同义词,但 Alexa 不会使用它们。很好的例子:

Alexa,谁是对的,我还是你? (作品)

Alexa,谁是对的,你还是我? (不会工作)

但在 JSON 中它说:

                                "value": "me or you",
                                "synonyms": [
                                    "you or me"
                                ]

但我认为为此我需要问另一个问题......

我去了 Alexa 开发者控制台,测试选项卡,写道:

“alexa,问大佬谁是对的,我还是我丈夫”

她说:

嗯,我不知道。

JSON 输入和输出窗口中没有任何内容,但我在设备日志中发现了这一行:

[21:11:35:676] - 事件:Text.TextMessage

我点击了那里,它打开了这个(如果需要的话):


    "event": 
        "header": 
            "namespace": "Text",
            "name": "TextMessage",
            "messageId": "messageId",
            "dialogRequestId": "numbers-and-letters-separated-with-sashes-that-i-deletedxxxxxxxxxxxxxxxxxxxxxxxxxxx506"
        ,
        "payload": 
            "textMessage": "alexa, ask mighty righty who is right, me or my husband"
        
    ,
    "context": [
        
            "header": 
                "namespace": "System",
                "name": "SettingsState",
                "payloadVersion": "1"
            ,
            "payload": 
                "settings": [
                    
                        "key": "com.amazon.alexa.characteristics.viewport.experiences",
                        "value": "[\"arcMinuteWidth\":\"246\",\"arcMinuteHeight\":\"144\",\"canRotate\":\"false\",\"canResize\":\"false\"]"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.shape",
                        "value": "RECTANGLE"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.pixelWidth",
                        "value": "1024"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.pixelHeight",
                        "value": "600"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.dpi",
                        "value": "160"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.currentPixelWidth",
                        "value": "1024"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.currentPixelHeight",
                        "value": "600"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.touch",
                        "value": "[\"SINGLE\"]"
                    ,
                    
                        "key": "com.amazon.alexa.characteristics.viewport.video",
                        "value": "\"codecs\": [\"H_264_42\",\"H_264_41\"]"
                    
                ]
            
        ,
        
            "header": 
                "namespace": "SpeechSynthesizer",
                "name": "SpeechState"
            ,
            "payload": 
                "token": "amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#ValidatedSpeakDirective_amzn1.ask.skill.some-kind-of-numbers-and-letters-here-i-deleted-it_they-are-seperated-with-dashes-and-1-underscore-in-the-middlexxxxxxxxxxxxxxxxxxxxxxxx",
                "offsetInMilliseconds": 1000,
                "playerActivity": "FINISHED"
            
        ,
        
            "header": 
                "namespace": "AudioPlayer",
                "name": "PlaybackState"
            ,
            "payload": 
                "token": "",
                "offsetInMilliseconds": 0,
                "playerActivity": "IDLE"
            
        ,
        
            "header": 
                "namespace": "Alerts",
                "name": "AlertsState"
            ,
            "payload": 
                "activeAlerts": [],
                "allAlerts": []
            
        ,
        
            "header": 
                "namespace": "AudioFocusManager",
                "name": "AudioFocusState"
            ,
            "payload": 
                "dialog": 
                    "component": "SpeechSynthesizer",
                    "idleTimeInMilliseconds": 0
                
            
        
    ]

之后的下一个日志

[21:11:36:703] - 指令:SkillDebugger.CaptureDebuggingInfo

它说


    "header": 
        "namespace": "SkillDebugger",
        "name": "CaptureDebuggingInfo",
        "messageId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx38"
    ,
    "payload": 
        "skillId": null,
        "timestamp": "2019-06-02T01:11:34.189Z",
        "dialogRequestId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx506",
        "skillRequestId": null,
        "type": "ConsideredIntents",
        "content": 
            "intents": [
                
                    "name": "<IntentForDifferentSkill>",
                    "confirmationStatus": null,
                    "slots": null
                ,
                
                    "name": "<IntentForDifferentSkill>",
                    "confirmationStatus": null,
                    "slots": null
                ,
                
                    "name": "<IntentForDifferentSkill>",
                    "confirmationStatus": null,
                    "slots": null
                
            ]
        
    

下一个 [21:11:36:932] - 指令:SpeechSynthesizer.Speak:


    "header": 
        "namespace": "SpeechSynthesizer",
        "name": "Speak",
        "messageId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "dialogRequestId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx506",
        "keys": 
            "isBlocking": true,
            "channel": "audio"
        
    ,
    "payload": 
        "caption": "Hmm, I don't know that.",
        "url": "https://tinytts.amazon.com/path to file here/resource.mp3",
        "format": "AUDIO_MPEG",
        "token": "amzn1.as-ct.v1.Domain:Global:Fallback#ACRI#DeviceTTSRendererV4_xxxxxxxxx5c",
        "ssml": "<speak><prosody volume=\"x-loud\">Hmm, I don&apos;t know that.</prosody><metadata><promptMetadata><promptId>NotUnderstood</promptId><namespace>SmartDJ.MusicQA</namespace><locale>en_US</locale><overrideId>default</overrideId><variant>2017_Variant 5</variant><condition/><weight>1</weight><stageVersion>Adm-xxxxxxxxxxxxxx</stageVersion></promptMetadata></metadata></speak>"
    


还有一些这样的日志,就是这样,这就是我发现的。

预期结果:

Alexa,问 Mighty Righty,谁是对的,我还是我的妻子? 你的妻子 (或来自 Player_BIOGRAPHY “我或我的妻子”的另一个随机回复)

实际结果:

Alexa,打开 Mighty Righty。 你好,你可以说...... 谁是对的,我还是我的妻子? 你的妻子 (或来自 Player_BIOGRAPHY “我或我的妻子”的另一个随机回复)

如您所见,获得响应的方式要长得多(取决于 Mighty Righty 的欢迎响应)

请帮忙! (我不是程序员,我只是跟着一个教程)

【问题讨论】:

问题不一定出在代码上。你能分享你的控制台设置吗?当您说“Alexa,问 Mighty Righty ....”时,意图表达、插槽以及传入的请求/事件是什么,这些将发送到您的 Lambda。只需将所有技能 ID 和敏感数据替换为 xxxxx。 从哪里粘贴? AWS 控制台显示:选择一个测试事件。测试。或者从 alexa 开发人员控制台,从测试选项卡,它显示 JSON 输入和输出(如果当我说 alexa 时没有输出,请询问强大的权利,谁是正确的我或你)。我按照你说的粘贴了 JSON 文件。 对于同义词,Alexa 不会自动为您更改值。相反,您会得到slot.resolutions,您必须在 Lambda 中切换值。看看这个答案:***.com/questions/48638353/… 对于 Alexa 请求,请查看 Alexa 控制台测试聊天并在输入“Alexa,问 Mighty Righty 谁是对的,我还是我丈夫”后抓住“输入”部分。这显示了发送到您的 Lambda 的内容。那么您的 Lambda 出于某种原因没有使用输出处理它,因此查看输入可能会解释原因。 我转到测试选项卡,在 JSON 输入和输出窗口中什么都没有。我在设备日志中发现了一些我认为是 JSON 格式的日志。你能看一下,也许这就是你的意思。 【参考方案1】:

当 Alexa 无法理解技能之外的输入,因此无法识别您在问什么或要使用什么技能时,会发送此错误消息“嗯,我不知道”。因此,插槽或意图不应该是错误。

Alexa 捕获语音输入时,并没有插入任何标点符号,而逗号等标点符号似乎破坏了 Alexa 理解输入的能力。

所以在使用 Alexa 控制台测试聊天时,不要在文本输入中写入任何标点符号。

在使用语音进行测试时,请清楚地发音并仔细检查您的日志以查看 Alexa 如何解释语音。您使用技能的次数越多,Alexa 就越应该学会正确地捕捉关键词。

【讨论】:

绝对正确,我注意到过了一会儿她正确地拿起了强大的权利。但起初她听到我的茶对茶,或类似的东西。但后来她做对了。 我想我需要再次讨论如何教她理解同义词

以上是关于“Alexa,打开 Mighty Righty” - 有效 /// “Alexa,问 Mighty Righty 谁是对的,我还是我丈夫”不起作用(嗯,我不知道那个)的主要内容,如果未能解决你的问题,请参考以下文章