首页 > 解决方案 > bixby 在测验示例中使用音频

问题描述

我正在尝试修改Bixby 的测验示例以使其与音频播放器一起使用。我想构建基本的“猜歌游戏测验”,我想在提示后播放音频。但我坚持 Bixby 的逻辑。并且不确定我应该使用什么模型结构。

我添加PlayAudio.model.bxb到模型中:

action (PlayAudio) {
  description (plays audio of quiz)
  type (Calculation)
  collect {
    input (quiz) {
      type (Quiz)
      min (Required) max (One)
    }

    computed-input (quiz.audioToPlay) {
      description (By passing in the AudioInfo object to the PlayAudio action, we ask the client to play our sound.)
      type (audioPlayer.Result)
      compute {
        intent {
          goal: audioPlayer.PlayAudio
          value: $expr(quiz.audioToPlay)
        }
      }
      hidden
    }
  }
  output (Quiz)
}

并改变了开始UpdateQuiz.model.bxb

action (UpdateQuiz) {
  type (Search)
  description (Compares the user's answer to the correct answer and updates your score and move to the next question)
  collect {
    input (answer) {
      type (Answer)
      min (Required) max (One)
    }
    input (quiz) {
      type (Quiz)
      min (Required) max (One)
      validate {
       if (quiz.audioToPlay != null) {
        replan {
          intent {
            goal: PlayAudio
            value { $expr(quiz) }
          }
        }
        }           
       }
      }
    }
  output (Quiz)
}

它在用户回答后播放音频,但在 Bixby 问题后不播放。我了解我添加了音频意图作为答案验证的一部分,并且验证将在答案后执行,但我不确定如何使其正确播放音频。

标签: javascriptsamsung-mobilebixby

解决方案


T 在我更改UpdateQuiz模型的问题后播放音频。

action (UpdateQuiz) {
  type (Search)
  description (Compares the user's answer to the correct answer and updates your score and move to the next question)
  collect {

    input (quiz) {
      type (Quiz)
      min (Required) max (One)
      validate {
       if (exists(quiz.audioToPlay) && !quiz.completed) {
        replan {
          intent {
            //goal: UpdateQuiz
            goal: PlayAudio
            value { $expr(quiz) }
          }
        }
        }           
       }
      }

      input (answer) {
      type (Answer)
      min (Required) max (One)
    }
    }
  output (Quiz)
}


推荐阅读