Распознавание речи TwiML не работает в локальном приложении Node.js. - PullRequest
0 голосов
/ 10 апреля 2019

Я использую Twilio, с помощью телефонного номера и webhook для переадресации звонков в мое локальное приложение Node.js. Ngrok используется для переадресации вызовов через http-порт 1337 в мое приложение Node.js, работающее локально.
Вызов правильно перенаправляется в локальное приложение с исходящим ответом по умолчанию. Но когда twiml.gather перенаправляет запрос в блок fact-command, код распознавания речи не работает.

Вот код:

const http = require('http');
const VoiceResponse = require('twilio').twiml.VoiceResponse;

http
  .createServer((req, res) => {
    // Create TwiML response
    const twiml = new VoiceResponse();

    // twiml.say('Hello from your pals at Twilio! Have fun.');
    twiml.gather({
      input: 'speech',
      timeout: 3,
      hints: 'cat, numbers, chuck norris',
      action: '/fact-command'    // Route to a twilio Speech Recognition event handler
    }).say('Welcome to the Twilio Facts hotline. Please say cat for cat facts, number for trivia about numbers, or chuck norris for a random chunk of chuck norris knowledge.');

    res.writeHead(200, { 'Content-Type': 'text/xml' });
    res.end(twiml.toString());


    var url = req.url;
    if(url ==='/fact-command'){
        console.log("This is a Twilio route");
        exports.handler = function(context, event, callback) {
          const twiml = new Twilio.twiml.VoiceResponse();

          const command = event.SpeechResult.toLowerCase();

          twiml.say(`You said ${command}. I'll give you a ${command} fact.`); // Speech is not getting recognized

          callback(null, twiml);
        };

    }

  })
  .listen(1337, '127.0.0.1');

console.log('TwiML server running at http://127.0.0.1:1337/');


Как распознать речь и сохранить ее в переменной с помощью TwiML и локального приложения Node.js?

...