从twilio访问transcriptionText

我想访问转录文本,这些文本是通过在我的Twilio账户中转录生成的,因为我想将用户logging的响应作为文本进行比较

twiml.say('Hi there! Please speak your response after the beep,-Get ready!') .record({ transcribe:true, timeout:5, maxLength:30, transcribeCallback:'/recording', action:'/recording' }); app.post('/recording', (request,response) => { if(transcriptionText=='yes'){ twiml.say('thank you for positive response'); } response.type('text/xml'); response.send(twiml.toString()); }); 

Twilio开发者在这里传道。

当使用<Record> 转录时,录制完成后,调用将继续向同步请求action属性。 无论您从action属性url返回的内容都将控制该通话。

然而,实际的转录需要更多的时间,当你得到一个webhook到transcribeCallback URL时,它是在调用的上下文之外asynchronous完成的。 所以,返回TwiML根本不会影响通话。

您将通过检查请求的正文来获取转录文本。 有很多参数发送到transcribeCallback ,但你正在寻找的是TranscriptionText 。 在你的Node.js应用程序中,看起来像Express,你可以通过调用request.body.TranscriptionText来获得它。

如果您希望在收到转录callback时影响通话,则需要使用REST API来修改通话并将其redirect到新的TwiML 。

让我知道这是否有帮助。

[编辑]

从评论中,我可以看到你正试图从口头回应中驱动部分电话。 由于需要完成转录,因此不会立即调用transcribeCallback URL,所以您需要一个action 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()); }); 

最后,当你获得转录回拨时,你可以通过某种方式从转录的文本中找出路线,然后将现场呼叫redirect到一个新的端点,以新的信息进行呼叫。

 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); }) });