首页 > 解决方案 > 为什么每当我在插槽中使用“白色”一词时,Alexa 会说“请求的技能响应有问题”?

问题描述

我正在制作一个带有 Raspberry Pi 和 LED 灯条的 Alexa 小工具,在我将插槽值添加到 AMAZON.Color 插槽之前,一切都运行良好。我添加了 CSS3 指定的颜色,包括白色,但现在我测试了除白色之外的所有颜色。当我使用“白色”这个词时,Alexa 说“请求的技能响应有问题”,但 CloudWatch Logs 中没有显示任何内容,我的小工具上也没有出现错误。

解决方法:

拉姆达代码:

# Recieves the solid_color intent and sends the solid_color directive to the gadget 
class solid_colorHandler(AbstractRequestHandler):
    
    # Determines what request type this handler handles
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("solid_color")(handler_input)

    # Handler
    def handle(self, handler_input):
        
        logger.info("== solid_color Intent ==")
        
        response_builder = handler_input.response_builder
        
        # Get connected gadget endpoint ID.
        endpointId = get_connected_endpointId(handler_input)

        # If there are any valid endpoints, send a directive.
        if endpointId != None:
            
            # Get slots
            slots = handler_input.request_envelope.request.intent.slots
            
            response = (response_builder
                .speak('')
                .add_directive(Directive('solid_color', endpointId, payload=slots))
                .set_should_end_session(True)
                .response)

        # If there are no endpoints, fail gracefully.
        else:
            response = no_endpoint_response(response_builder)
        
        return response

小工具代码:

    def on_custom_deskdisplay_solid_color(self, directive):
        slots = json.loads(directive.payload.decode("utf-8"))
        logger.info(slots)

        # YOUR CODE HERE
        print('solid_color called via Alexa with slots: \n' + str(slots))

        if self.animation != None:
            self.animation.terminate()
            self.animation = None

        colorName = getSlotValue(directive, 'color')
        
        if colorName != 'rainbow':
            rgb = name_to_rgb(colorName)
            color = Color(rgb.red, rgb.green, rgb.blue)

            for i in range(self.strip.numPixels()):
                self.strip.setPixelColor(i, color)
            
            self.strip.show()

        else:
            rainbow(self.strip)

槽值

...
palevioletred,palevioletred,pale violetred
mediumvioletred,mediumvioletred,medium violetred
white,white,white
snow,snow,snow
honeydew,honeydew,honeydew
...

标签: pythonalexaalexa-skills-kitalexa-voice-servicealexa-slot

解决方案


推荐阅读