我最近开始为Pepper构建一个Javascript程序。我的目标是让pepper倾听人们说的话,或者说Hello,或者让Pepper在Javascript的WordRecognized事件中基于关键字'Hello/ animation‘制作动画。
到目前为止,我可以使用JavaScript在平板电脑上显示两个按钮,让佩珀在一个按钮下说你好,在另一个按钮上执行动画。点击按钮可以工作,但是我不能通过使用Qi Javascript SDK (http://doc.aldebaran.com/2-4/dev/js/index.html )使它对WordRecognized事件起作用。我浏览了这里提到的链接,并提出了下面的代码片段,它让Pepper在听到识别的单词时说出单词。只是想知道我在代码中还遗漏了什么让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
});发布于 2018-06-11 15:30:16
你给出的代码片段不会工作,因为这是:
var asr = session.service('ALSpeechRecognition');意味着asr变量是一个未来变量,所以不能对它调用asr.unsubscribe()。
您必须将所有内容都包装在session.service(...).then(function(asr) { ...}中才能正常工作,就像使用ALMemory一样。
语法可能有点笨拙,我通常使用一个小的帮助器库robotutils.qim.js,它使代码更具可读性,并且有一个用于订阅ALMemory的帮助程序。
https://stackoverflow.com/questions/50785702
复制相似问题