Node.js Twilio如何在switch语句中添加暂停
我有五个菜单,用户可以从中选择当他们拨打电话号码。每个菜单有4到6个选项。使用.say在Twilio中,所有选项都说得非常快,我想放慢速度。每句话后面加个逗号并不能让它慢下来,所以我一直在尝试使用。运气不好的话暂停一下。我的想法是使用4到6。比如在一个箱子里,在每个箱子之间暂停2秒钟。比如 在此方面的任何帮助都将不胜感激 我试过了Node.js Twilio如何在switch语句中添加暂停,node.js,twilio,Node.js,Twilio,我有五个菜单,用户可以从中选择当他们拨打电话号码。每个菜单有4到6个选项。使用.say在Twilio中,所有选项都说得非常快,我想放慢速度。每句话后面加个逗号并不能让它慢下来,所以我一直在尝试使用。运气不好的话暂停一下。我的想法是使用4到6。比如在一个箱子里,在每个箱子之间暂停2秒钟。比如 在此方面的任何帮助都将不胜感激 我试过了 // Test Menu case '6': twiml.gather({numDigits: 1}) .say('I wi
// Test Menu
case '6':
twiml.gather({numDigits: 1})
.say('I will pause 5 seconds starting now!')
.pause(5)
.say('Now for the second sentence.');
twiml.redirect('');
break;
但是我在调试中遇到了以下错误
错误-82002
Twilio函数响应错误
您的函数调用导致状态代码5xx。
可能原因
Your Function timed out before responding
Your Function returned an error response
可能的解决办法
Your Function must contain a callback.
Make sure you place the Function callback callback(err, response) is placed correctly in your Function code.
If you are using a JavaScript promise, make sure the callback is called in both success and catch blocks.
Your Function responded with an error.
下面的代码按原样工作,但在每种情况下都会播放fast选项。我试图在测试菜单中使用.say和.pause(案例6),但在我尝试的每个想法中都失败了
exports.handler = function(context, event, callback)
{
let finishOnKey = '0';
let twiml = new Twilio.twiml.VoiceResponse();
switch (event.Digits)
{
// Case 1
case '1':
twiml.gather({numDigits: 1})
.say(‘Message.');
twiml.redirect('');
break;
// Case 2
case '2':
twiml.gather({numDigits: 1})
.say(‘Message.');
twiml.redirect('');
break;
//Case 3
case '3':
twiml.gather({numDigits: 1})
.say('Message.');
twiml.redirect('');
break;
//Case 4
case '4':
twiml.gather({numDigits: 1})
.say('Message. ');
twiml.redirect('');
break;
//Case 5
case '5':
twiml.gather({numDigits: 1})
.say('Message.');
twiml.redirect('');
break;
// Test Menu
case '6':
twiml.gather({numDigits: 1})
.say('I will pause 5 seconds starting now!')
.pause(5);
.say('Now for the second sentence.');
twiml.redirect('');
break;
// Pressing * repeats the current menu
case '*':
twiml.gather({numDigits: 1,action:'/XXX_General_Info'})
.say(‘Message.');
break;
// Main menu
default:
twiml.gather({numDigits: 1,action:'/XXX'})
.say('Message. To repeat these options press star. To go back
to the main menu press zero. To end this call just hang up,
or press pound.');
}
callback(null, twiml);
};
我的建议是使用Polly的语音合成标记语言(SSML),正如Devin所建议的那样。确保您的Twilio函数Twilio helper库是最新的(在“配置”下)。如果显示为3.6.3,则表示您使用的是较旧的库,必须输入较新的版本。Twilio节点帮助器库的最新版本可在[此处][1],(从今天起为3.36.0) 下面是示例Twilio Function Node.js代码,帮助您正确开始。玩得开心
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let gather = twiml.gather({numDigits: 1});
gather.say({voice: 'Polly.Joanna'}, 'Hi')
.ssmlBreak({strength: 'x-weak',time: '2000ms'});
gather.say({voice: 'Polly.Joanna'}, 'How are you?');
callback(null, twiml);
};
say动词支持Amazon Polly,其中包括一种设置语速的方法:下面的代码非常适合在两个句子之间设置停顿,但在switch语句中似乎不起作用,因为当我按下一个键时,twilio没有检测到它。稍微更改了代码。您只需使用代码,以确保Say嵌套在聚集中。
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let gather = twiml.gather({numDigits: 1});
gather.say({voice: 'Polly.Joanna'}, 'Hi')
.ssmlBreak({strength: 'x-weak',time: '2000ms'});
gather.say({voice: 'Polly.Joanna'}, 'How are you?');
callback(null, twiml);
};