我怎样才能告诉收集在演讲开始前等待一段时间,然后开始收集呢

2024-04-25 14:10:14 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,接受来电和收集语音。下面是我使用Python和Flask编写的代码示例

# more code above
resp.gather(input='speech dtmf', timeout=3, speech_timeout=4, action='/gather', method='POST')
resp.redirect('/gather')

# more code in between

@app.route("/gather", methods=['GET', 'POST'])
def gather():
    #print("gather: Entry ")
    resp = VoiceResponse()
    sid = request.form['CallSid']
    SpeechResult = request.values.get("SpeechResult", "")

    params = urllib.parse.urlencode({"SpeechResult": SpeechResult})
    print("0 gather: " + str(params).lower())

但是,调用此函数会导致:

   0 gather: speechresult=

当我自己调用这个应用程序时,我注意到它等待了5秒钟才开始提示。我怎样才能告诉聚集在聚集前5秒开始

我尝试在resp.gather之前添加time.slpeep(5)。。。但没用


Tags: 代码flask示例requestmoretimeoutcode语音
1条回答
网友
1楼 · 发布于 2024-04-25 14:10:14

Twilio开发者福音传道者

我不知道你在说什么

我缺少的是,您的初始^{}似乎没有请求用户的输入。当<Gather>等待输入时,这将导致~5秒的静默,然后放弃并转到/gather端点,而SpeechResult中没有任何内容

如果您想对用户说些什么让他们回答,您应该在<Gather>中使用^{},如下所示:

gather = resp.gather(input='speech dtmf', timeout=3, speech_timeout=4, action='/gather', method='POST')
gather.say('Please answer the question')

也可以在<Gather>中使用^{}^{}

如果有帮助,请告诉我

相关问题 更多 >