用正确的语音进行计数

时间:2019-07-05 13:33:34

标签: alexa alexa-skills-kit alexa-skill

我为alexa创建了一个简单的测验技能,但需要一些帮助才能使其正常工作。

我使用以下示例:https://github.com/alexa/skill-sample-nodejs-trivia/blob/en-US/lambda/custom/index.js

效果很好,但这是我的问题:

function startGame(newGame, handlerInput) {
  const requestAttributes = handlerInput.attributesManager.getRequestAttributes();
  let speechOutput = newGame
    ? requestAttributes.t('NEW_GAME_MESSAGE', requestAttributes.t('GAME_NAME'))
      + requestAttributes.t('WELCOME_MESSAGE', GAME_LENGTH.toString())
    : '';
  const translatedQuestions = requestAttributes.t('QUESTIONS');
  const gameQuestions = populateGameQuestions(translatedQuestions);
  const correctAnswerIndex = Math.floor(Math.random() * (ANSWER_COUNT));

  const roundAnswers = populateRoundAnswers(
    gameQuestions,
    0,
    correctAnswerIndex,
    translatedQuestions
  );
  const currentQuestionIndex = 0;
  const spokenQuestion = Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0];
  let repromptText = requestAttributes.t('TELL_QUESTION_MESSAGE', '1', spokenQuestion);
  for (let i = 0; i < ANSWER_COUNT; i += 1) {
    repromptText += `${i + 1}. ${roundAnswers[i]}. `;
  }

  speechOutput += repromptText;
  const sessionAttributes = {};

  const translatedQuestion = translatedQuestions[gameQuestions[currentQuestionIndex]];

  Object.assign(sessionAttributes, {
    speechOutput: repromptText,
    repromptText,
    currentQuestionIndex,
    correctAnswerIndex: correctAnswerIndex + 1,
    questions: gameQuestions,
    score: 0,
    correctAnswerText: translatedQuestion[Object.keys(translatedQuestion)[0]][0]
  });

我已将行更改为:

const currentQuestionIndex = 0;
  const spokenQuestion = Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0];
  let repromptText = requestAttributes.t('TELL_QUESTION_MESSAGE','1', spokenQuestion);
  for (let i=0; i < ANSWER_COUNT; i += 1) {
    repromptText += `${ANTWORT_ANTWORT} ${ANTWORT_TEXT[i]}: ${roundAnswers[i]}. `;
  }

效果很好,但仅适用于第一个问题,因此我喜欢将其包含在以下所有问题中。我被困了24小时,现在问你们要不要动脑筋

谢谢

0 个答案:

没有答案