用用户指定间隔计数的Alexa技能

发布于 2025-02-10 11:53:14 字数 332 浏览 3 评论 0原文

我正在尝试创建一种在用户指定的间隔中计入用户指定数字的技能。 例如,我会说Alexa以2秒的时间间隔

我可以在python中做到这一点,但是在编码Alexa技能方面,我是个菜鸟。显然,Alexa现在拥有Python服务。因此,我只能编辑lambda_function.py代码。 如何将Python脚本与Alexa代码库集成?

Python代码将很简单:

from time import sleep
for num in range(1, user_end):
    print(num)
    sleep(user_interval)

I am trying to create a skill that counts to a user specified number in user specified intervals.
For example I would say Alexa count to 30 in intervals of 2 seconds

I can do it in python but i am a noob when it comes to coding alexa skills. Apparently Alexa now has a python service. So i can just edit the lambda_function.py code.
How do i integrate my python script with the alexa code base?

The python code would be as simple as:

from time import sleep
for num in range(1, user_end):
    print(num)
    sleep(user_interval)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2025-02-17 11:53:14

应该允许您创建这样的动态响应。

这是对我有用的示例文档和数据源。

文档

{
    "type": "APLA",
    "version": "0.91",
    "mainTemplate": {
        "parameters": [
            "payload"
        ],
        "item": {
            "type": "Sequencer",
            "data": "${payload.counts}",
            "items": [
                {
                    "type": "Speech",
                    "content": "${data}"
                },
                {
                    "type": "Silence",
                    "duration": "${payload.intervalMs}"
                }
            ]
        }
    }
}

数据源:

{
    "counts": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    "intervalMs": 2000
}

您的技能可以将这些指令添加到其响应中:

{
  "type": "Alexa.Presentation.APLA.RenderDocument",
  "token": "developer-provided-string",
  "document": {
    "type": "APLA",
    "version": "0.91",
    "mainTemplate": {
      "parameters": [
        "payload"
      ],
      "item": {
        "type": "Sequencer",
        "data": "${payload.counts}",
        "items": [
          {
            "type": "Speech",
            "content": "${data}"
          },
          {
            "type": "Silence",
            "duration": "${payload.intervalMs}"
          }
        ]
      }
    }
  },
  "datasources": {
    "counts": [
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19,
      20,
      21,
      22,
      23,
      24,
      25,
      26,
      27,
      28,
      29,
      30
    ],
    "intervalMs": 2000
  }
}

APL for Audio should allow you to create a dynamic response like this.

Here's a sample document and data source that works for me.

Document

{
    "type": "APLA",
    "version": "0.91",
    "mainTemplate": {
        "parameters": [
            "payload"
        ],
        "item": {
            "type": "Sequencer",
            "data": "${payload.counts}",
            "items": [
                {
                    "type": "Speech",
                    "content": "${data}"
                },
                {
                    "type": "Silence",
                    "duration": "${payload.intervalMs}"
                }
            ]
        }
    }
}

Data Source:

{
    "counts": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
    "intervalMs": 2000
}

Your skill can piece those together an add the following directive to its response:

{
  "type": "Alexa.Presentation.APLA.RenderDocument",
  "token": "developer-provided-string",
  "document": {
    "type": "APLA",
    "version": "0.91",
    "mainTemplate": {
      "parameters": [
        "payload"
      ],
      "item": {
        "type": "Sequencer",
        "data": "${payload.counts}",
        "items": [
          {
            "type": "Speech",
            "content": "${data}"
          },
          {
            "type": "Silence",
            "duration": "${payload.intervalMs}"
          }
        ]
      }
    }
  },
  "datasources": {
    "counts": [
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19,
      20,
      21,
      22,
      23,
      24,
      25,
      26,
      27,
      28,
      29,
      30
    ],
    "intervalMs": 2000
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文