gpt4 book ai didi

python - 在后台运行计时器 x 秒 [Alexa 技能]

转载 作者:行者123 更新时间:2023-11-28 19:28:40 24 4
gpt4 key购买 nike

我正在制作一个返回音频但仅持续 x 秒的函数。

如果用户说

给我放一首歌 x 秒

我正在播放歌曲,但需要在 X 秒后取消播放。因此,我的计划是在运行音频之前启动计时器 x 秒。然后,一旦计时器到时,就可以设置另一个功能的通知,该功能将返回一个新的声音,说您的时间到了。

虽然我需要一种方法来启动后台计时器,但我已经理解了逻辑。

def start_audio():
card_title = "Start Audio"
session_attributes = {}


sound_url = 'https://s3.amazonaws.com/........mp3'

speech_output = "<speak><audio src='{}'/> </speak>".format(sound_url)



should_end_session = False
return build_response(session_attributes, myCustomSSML(
card_title, speech_output, None, should_end_session))

def myLaunchIntent():
""" If we wanted to initialize the session to have some attributes we could
add those here
"""
session_attributes = {}
card_title = "Welcome"
speech_output = "Welcome to your custom Alexa application!"

return start_audio()

目前:

-> 启动时

->返回开始音频

-> 我需要在 X 秒内传递

-> X 秒将启动计时器

-> 一旦定时器完成调用另一个停止的函数

如果有人可以引导我朝着正确的方向前进,例如向我展示如何在 x 秒内运行后台计时器然后调用另一个函数,那么我将能够接管并将其扩展到更高的水平。

最佳答案

因为 Alexa 作为请求/响应应用程序工作,一旦您发送响应,就没有更多的方法来控制播放,直到用户执行某些操作并且新请求到达您的处理程序。

我可以想象两种可能的方式来实现所需的功能。要么即时生成一个简短的音频剪辑(使用 FFmpeg 之类的东西),要么让它们在所有可能的持续时间(1 秒、2 秒、3 秒...)内预先生成并提供适当的音频剪辑。

关于python - 在后台运行计时器 x 秒 [Alexa 技能],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54174225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com