python - 为什么每当我在插槽中使用“白色”一词时,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
...
解决方案
推荐阅读
- php - 如何在 PHP 中更改查询结果页面的 URL?
- spring - Intellij 问题解决了 spring kotlin 的依赖关系
- bash - 丢弃curl命令中变量的修改内容
- selenium - 在尝试了仍然面临的所有解决方案之后-system.property org.testng.TestNGException:无法实例化类
- mysql - 如何在查询的 WHERE 部分使用定义的 AS 别名?
- d3.js - C3 - 在折线图上添加自定义标签
- xamarin - webview上的打印按钮不起作用
- sorting - 我想检查比较运算符是真还是假
- javascript - 带有附加版本号的 gzip .js 和 .css 文件
- java - 如何在 tess4j 4.1 版中将字符列入白名单。*