Dialogflow обнаруживает звук с экспресс не работает - PullRequest
0 голосов
/ 14 ноября 2018

Я попытался сохранить аудиофайл с клиента и отправил его в диалоговое окно для обнаружения. Но я не мог получить сообщение об ошибке. SessionClient работает нормально, если я перехожу из req.pipe (). Запрос представляет собой WAV-файл.

router.post('/upload', function (req, res, next) {
  var timeCode = new Date();
  const filename = 'public/voiceFiles/' + timeCode.getTime() + '.wav';
  req.pipe(fs.createWriteStream(filename))
    .on('error', (e) => res.status(500).end(e.message))
    .on('close', () => {
      const readFile = util.promisify(fs.readFile);
      readFile(filename)
        .then(inputAudio => {
          // The audio query request
          const request = {
            session: sessionPath,
            queryInput: {
              audioConfig: {
                audioEncoding: encoding,
                sampleRateHertz: sampleRateHertz,
                languageCode: languageCode,
              },
            },
            inputAudio: inputAudio,
          };
          // Recognizes the speech in the audio and detects its intent.
          return sessionClient.detectIntent(request);
        })
        .then(responses => {
          console.log('Detected intent:');
          res.end(JSON.stringify(responses));
        })
        .catch(err => {
          console.error('ERROR:', err);
          res.end(err)
        });
      // [END dialogflow_detect_intent_audio]      
    })
});
...