我正在使用Python在Tropo中创建一个应用程序,我想知道我是否可以创建一个本地的小语法。我读过关于外部语法SRGS和GRXML的文章,但是我可以在代码中使用Python列表来创建一个吗?下面是我正在尝试做的事情。
food = ['cheeseburger', 'hot dog', 'salad']
ask("What food would you like?",
#{'choices': "cheeseburger, hot dog, salad",
{'choices': food,
'attempts':3,
'onChoice': fill,
'onBadChoice': nomatch,
'onTimeout': noinput })上面的代码可以编译,但在遇到这个问题时会挂起。
发布于 2015-12-02 03:26:37
如果你想让Tropo询问呼叫者“你想要什么食物”,并给他们三次尝试,让他们用“食物”中的一个短语回答,尝试发送以下json响应:
{
"tropo": [
{
"ask": {
"choices": {
"value": "cheeseburger, hot dog, salad",
"mode": "speech",
"terminator": "#"
},
"attempts": 3,
"name": "foodchoice",
"recognizer": null,
"required": null,
"say": {
"value": "What food would you like"
}
}
},
{
"on": {
"event": "continue",
"name": null,
"next": "/fill",
"required": true
}
},
{
"on": {
"event": "incomplete",
"name": null,
"next": "/noinput",
"required": true
}
},
{
"on": {
"event": "error",
"name": null,
"next": "/nomatch",
"required": true
}
}
]
}要准确回答您的问题,您需要了解Python Tropo库。我不熟悉python one,但是Tropo的Java和NodeJS库似乎不是date...so的,如果Python one也是如此,那么您将不得不做更多的工作来构建和返回这个JSON对象。
发布于 2016-01-09 06:36:27
根据Tropo文档中的示例:
result = ask("What's your favorite color? Choose from red, blue or green.", {
"choices":"red, blue, green"})
say("You said " + result.value)
log("They said " + result.value)choices是一个字符串,而不是一个列表,所以你应该这样做:
food = "cheeseburger, hot dog, salad"
ask("What food would you like?",
{'choices': food,
'attempts':3,
'onChoice': fill,
'onBadChoice': nomatch,
'onTimeout': noinput })https://stackoverflow.com/questions/33878899
复制相似问题