AmazonAlexa-未定义的语音响应

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (17)

我试图在“SetLanguageIntent”中调用“AskQuestion”,使用Alexa事实技能蓝图为用户构建一个演讲。

'SetMyLanguageIntent': function() {
    this.attributes['language'] = this.event.request.intent.slots.languages.value;
    var language = this.attributes['language'];

    this.response
      .speak('Okay, I will ask you some questions about ' +
        language + '. Here is your first question.' +
        this.AskQuestion).listen(this.AskQuestion);
    this.emit(':responseReady');
  },

'AskQuestion': function() {
    var language = this.attributes['language'];
    var currentQuestion = flashcardsDictionary[this.attributes['currentFlashcardIndex']].question;

    return 'In ' + language + ', ' + currentQuestion;
  },

这是服务器的响应:

{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "ssml": "<speak> Okay, I will ask you some questions about undefined. Here is your first question.undefined </speak>",
      "type": "SSML"
    },
    "reprompt": {
      "outputSpeech": {
        "ssml": "<speak> undefined </speak>",
        "type": "SSML"
      }
    },

Alexa在回答中说出“未定义”这个词,这是对话:“好的,我会问你一些关于undefined的问题。这是你的第一个问题.undefined”

为什么回复“未定义”?以及如何解决这个问题?

这是整个代码:

'use strict';

var Alexa = require('alexa-sdk');

var flashcardsDictionary = [{
    question: 'how do you find the length of a string?',
    rubyAnswer: 'length',
    pythonAnswer: 'Len',
    javascriptAnswer: 'length'
  },
  {
    question: 'how do you print to the console or terminal?',
    rubyAnswer: 'puts',
    pythonAnswer: 'print',
    javascriptAnswer: 'console.log'
  },
  {
    question: 'are boolean terms capitalized or not capitalized?',
    rubyAnswer: 'not capitalized',
    pythonAnswer: 'capitalized',
    javascriptAnswer: 'not capitalized'
  }
];

var DECK_LENGTH = flashcardsDictionary.length;

var handlers = {
  // Open Codecademy Flashcards
  'LaunchRequest': function() {
    this.attributes['language'] = '';
    this.attributes['numberCorrect'] = 0;
    this.attributes['currentFlashcardIndex'] = 0;

    this.response
      .listen('Welcome to Flashcards. In this session, do you want to test' +
        ' your knowledge in Ruby, Python, or Javascript?').speak(
        'Which language would you like to practice?');
    this.emit(':responseReady');
  },

  'SetMyLanguageIntent': function() {
    this.attributes['language'] = this.event.request.intent.slots.languages.value;
    var language = this.attributes['language'];

    this.response
      .speak('Okay, I will ask you some questions about ' +
        language + '. Here is your first question.' +
        this.AskQuestion).listen(this.AskQuestion);
    this.emit(':responseReady');
  },

  // User gives an answer
  'AnswerIntent': function() {
    var userAnswer = this.event.request.intent.slots.answer.value;
    var language = this.attributes['language'];
    var languageAnswer = language + userAnswer;
    var correctAnswer = flashcardsDictionary[this.attributes['currentFlashcardIndex']][languageAnswer];


    if (userAnswer === correctAnswer) {
      this.attributes['numberCorrect']++;
      var numberCorrect = this.attributes['numberCorrect'];

      this.response
        .speak('Nice job! The correct answer is ' + correctAnswer + '. You ' +
          'have gotten ' + numberCorrect + ' out of ' + DECK_LENGTH + ' ' +
          language + ' questions correct.' + this.AskQuestion)
        .listen(this.AskQuestion);


    } else {
      var numberCorrect = this.attributes['numberCorrect'];

      this.response
        .speak('Sorry, the correct answer is ' + correctAnswer + '. You ' +
          'have gotten ' + numberCorrect + ' out of ' + DECK_LENGTH + ' ' +
          language + ' questions correct. Here is your next question.' +
          this.AskQuestion).listen(this.AskQuestion);
    }

    this.attributes['currentFlashcardIndex']++;

    this.emit(':responseReady');
  },

  // Test my {language} knowledge
  'AskQuestion': function() {
    var language = this.attributes['language'];
    var currentQuestion = flashcardsDictionary[this.attributes['currentFlashcardIndex']].question;

    return 'In ' + language + ', ' + currentQuestion;
  },

  // Stop
  'AMAZON.StopIntent': function() {
    this.response.speak('Ok, let\'s play again soon.');
    this.emit(':responseReady');
  },

  // Cancel
  'AMAZON.CancelIntent': function() {
    this.response.speak('Ok, let\'s play again soon.');
    this.emit(':responseReady');
  }
};

exports.handler = function(event, context, callback) {
  var alexa = Alexa.handler(event, context);
  alexa.registerHandlers(handlers);
  alexa.execute();
};
提问于
用户回答回答于

使用this.AskQuestion()而不是this.AskQuestion作为AskQuestion函数而不是对象。

热门问答

数据万象持久化在JavaScript SDK中的问题?

可以的,有Domain参数。请参考:https://github.com/tencentyun/cos-js-sdk-v5/blob/master/csp/csp.html#L56

有谁用unity 3d 实现过对象的上传储存和者下载?

我不是米

腾讯 · 工程师 (已认证)

对象存储工程师
推荐

请正确填写bucket参数,bucket参数里面不要带上-appid

cos.sliceUploadFile支持断点续传吗?

如果用的是 cos-js-sdk,那么 cos.restartTask 是会断点续传的,用法没有问题。 PS: sdk 使用可以参考 demo.js https://github.com/tencentyun/cos-js-sdk-v5/blob/master/demo/demo...... 展开详请

使用独立H5接入人脸核身,在微信浏览器拍摄视频按钮无法点击?

旺仔小小鹿

社区 · 运营 (已认证)

Less is more
推荐

使用iframe会有问题 ,微信有限制,不允许使用iframe调用jsapi摄像头 ,微信里,不能用iframe

ios应该都不行的,安卓需要看是什么浏览器。

云服务器中ping不可达,请教一下如何恢复?

推荐已采纳
本地主机 ping 不通实例可能由以下问题导致: 目标服务器的设置不正确 域名没有正确解析 链路故障 在确保本地网络正常的前提下(即您可以正常 ping 通其他网站),可根据以下操作进行排查: 检查实例是否配置公网 IP 检查安全组设置 检查系统设置 检查域名是否备案 检查域名解...... 展开详请

为什么加固之后生成四个文件?

腾讯云@移动安全

腾讯 · 移动开发工程师 (已认证)

腾讯云移动安全前端开发
推荐

选择最后一个_legu_aligned_signed.apk 文件,这个是加固并已重签名的文件。

所属标签

扫码关注云+社区

领取腾讯云代金券