这里是 Twilio 开发者宣传员。
当使用transcription 和<Record> 时,一旦录制完成,调用将继续同步向action 属性发出请求。无论您从 action 属性 URL 返回什么,都将控制调用。
然而,实际的转录需要更多时间,当您获得到 transcribeCallback URL 的 webhook 时,它是在调用上下文之外异步完成的。因此,返回 TwiML 根本不会影响调用。
您将通过检查请求的正文获得转录文本。有很多parameters sent to the transcribeCallback,但您正在寻找的是TranscriptionText。在您的 Node.js 应用程序中,对我来说它看起来像 Express,您可以通过调用 request.body.TranscriptionText 来获取它。
如果您确实想在收到转录回调时影响通话,您需要use the REST API to modify the call and redirect it to some new TwiML。
让我知道这是否有帮助。
[编辑]
从 cmets 中,我可以看到您正试图通过语音响应来驱动部分呼叫。 transcribeCallback URL 不会立即调用,因为需要完成转录,因此您需要一个 action URL,您可以在等待时将调用者发送到该 URL。
因此,调整您的录制路径,为action 和transcribeCallback 设置不同的端点:
app.post("/voice", (request, response) => {
var twiml = new twilio.TwimlResponse();
twiml.say('Hi there! Please speak your response after the beep,-Get ready!')
.record({
transcribe:true,
timeout:5,
maxLength:30,
transcribeCallback:'/transcribe',
action:'/recording'
});
response.type('text/xml');
response.send(twiml.toString());
})
那么您的录制端点将需要让用户在 Twilio 转录文本时等待。
app.post('/recording', (request,response) => {
var twiml = new twilio.TwimlResponse();
// A message for the user
twiml.say('Please wait while we transcribe your answer.');
twiml.pause();
// Then redirect around again while we wait
twiml.redirect('/recording');
response.type('text/xml');
response.send(twiml.toString());
});
最后,当您收到转录回调时,您可以以某种方式从转录文本中找出课程,然后将实时呼叫重定向到一个新端点,该端点使用新信息进行呼叫。
app.post('/transcribe', (request, response) => {
var text = request.body.TranscriptionText;
var callSid = require.body.CallSid;
// Do something with the text
var courseId = getCourseFromText(text);
var accountSid = '{{ account_sid }}'; // Your Account SID from www.twilio.com/console
var authToken = '{{ auth_token }}'; // Your Auth Token from www.twilio.com/console
var client = new twilio.RestClient(accountSid, authToken);
// Redirect the call
client.calls(callSid).update({
url: '/course?courseId=' + courseId,
method: 'POST'
}, (err, res) => {
response.sendStatus(200);
})
});