如何缩短Twilio语音识别Gather动作的响应延迟?
Twilio语音识别通话延迟问题:用户停话后4-5秒才触发动作URL
使用Twilio和Node.js开发语音识别系统,目标是在通话中用户停止说话后立即播放音频片段,但目前存在严重延迟:用户停止说话后,Twilio调用Gather动作URL处理语音识别结果的间隔约为4-5秒。该延迟已记录在Twilio日志中(
),严重影响应用响应速度。
预期行为:用户停止说话后立即触发动作URL。
已尝试的操作:
- 调整speechTimeout:使用
speechTimeout: 'auto'及其他参数值,尝试快速检测语音结束 - 分析日志:确认延迟并非来自服务器端处理,而是Twilio内部问题
- 查阅文档:查看Twilio Gather文档寻找优化方案
- 参考同类问题:查阅相关问题但未找到直接解决延迟的方案
app.post('/voice-response', (req, res) => { logWithTimestamp('Handling voice response'); const twiml = new twilio.twiml.VoiceResponse(); // Gather speech input with a timeout twiml.gather({ input: ['speech'], action: `${process.env.BASE_URL}/gather`, // This URL handles the gathered speech speechTimeout: '1', // Automatically detect when speech has ended // enhanced: true, speechModel: "experimental_conversations", }); // If no input is received, play a message twiml.say('You need to say something'); res.type('text/xml'); res.send(twiml.toString()); logWithTimestamp('Sent TwiML response for gathering speech'); }); // Endpoint to handle the gather action response app.post('/gather', (req, res) => { logWithTimestamp(`Incoming Gather Request: ${JSON.stringify(req.body)}`); const twiml = new twilio.twiml.VoiceResponse(); if (req.body.SpeechResult) { logWithTimestamp(`Speech detected: ${req.body.SpeechResult}`); // If speech is detected, acknowledge the speech twiml.play(`${process.env.BASE_URL}/voice/output.mp3`); } else { logWithTimestamp('No speech detected, playing default message'); // If no speech is detected, play an audio message twiml.say('You need to say something'); } res.type('text/xml'); res.send(twiml.toString()); logWithTimestamp('Sent TwiML response for gather action'); });
内容的提问来源于stack exchange,提问作者Huzaifa Jalil
相关产品推荐
相关产品推荐

