【发布时间】:2018-06-10 16:21:04
【问题描述】:
我最近开始为 Pepper 构建一个 Javascript 程序。我的目标是让 Pepper 倾听人们所说的话,或者说 Hello,或者让 Pepper 根据 Javascript 中 WordRecognized 事件中的关键字“Hello/Animation”制作动画。
到目前为止,我可以使用 JavaScript 在平板电脑上显示两个按钮,让 Pepper 在按下一个按钮时说 Hello,并在按下另一个按钮时执行动画。单击按钮可以工作,但我无法通过使用 Qi Javascript SDK (http://doc.aldebaran.com/2-4/dev/js/index.html) 使其适用于 WordRecognized 事件。我浏览了这里提到的链接并想出了下面的代码 sn-p 使 Pepper 在听到识别的单词时说单词 Detected。只是想知道我在代码中还缺少什么让 Pepper 听单词并相应地执行操作?
//Start the Speech Recognition
var asr = session.service('ALSpeechRecognition');
//Define the Vocabulary
vocabulary = ["hello", "dance"];
//Set The Language To English and set the Vocabulary
asr = asr.then( function(asr) { return asr.setLanguage('English') }).then( function(asr){ return asr.setVocabulary(vocabulary, false); } );
console.log("Set the Language to English!");
//Register the Callback function for the Speech REcognition
asr.unsubscribe(); //De-Register if Existing from Before
asr.subscribe();
session.service("ALMemory").then(function (ALMemory) {
ALMemory.subscriber("wordRecognized").then(function (subscriber) {
// subscriber.signal is a signal associated to "wordRecognized"
subscriber.signal.connect(function (state) {
word = state.getData("wordRecognized")[1];
word.then( function() { session.service('ALTextToSpeech').say("A Keyword is Detected!") });
asr.unsubscribe();
}); //subscriber
}); //connect
}); //ALMemory
});
【问题讨论】: