【问题标题】:Access transcriptionText from twilio从 twilio 访问转录文本
【发布时间】:2016-12-17 05:11:42
【问题描述】:

我想访问已在我的 Twilio 帐户中转录生成的转录文本,因为我想将用户记录的响应作为文本进行比较

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

});

【问题讨论】:

    标签: node.js twilio twilio-twiml


    【解决方案1】:

    这里是 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。

    因此,调整您的录制路径,为actiontranscribeCallback 设置不同的端点:

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

    【讨论】:

    • 感谢您的回复,我的 transcribcallback 和操作 url 是相同的,即 /recording 但在 /recording 中,当我将 request.body.TranscriptionText 放入变量并将其传递给 twiml.say 时,它显示未定义。我可以访问 request.body.recordingUrl 但与转录无关
    • 转录需要很短的时间,因此不是对action URL 的第一次回调的一部分。您将收到另一个带有转录文本的 URL 回调,但是正如我所说,这不能直接影响调用。出于这个原因,我建议使用不同的 URL 在您的应用程序中使这一点显而易见。如果您想影响来自异步 transcribeCallback 的调用,那么您将需要使用我在原始答案中所说的 REST API。
    • 我应该在我的代码中进行哪些更改以访问 request.body.transcriptionText 以使用用户当前所说的值。我的 trascribcallback url 应该是什么?我对此很陌生,所以很难理解
    • 非常感谢我试试这个,但它如何摆脱 /recording 循环
    • 我尝试了您的解决方案,它一直在 /recording 中循环,并且没有进入 /transcribe
    猜你喜欢
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2015-03-14
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    相关资源
    最近更新 更多