我和我的学生正在使用 NAO 机器人。我们在 Java 中遇到语音识别问题。只有在单词被说出两次之后,我们才能让机器人从我们指定的词汇表中识别单词。谢谢,请参阅下面的代码以获取示例:
public class SpeechRecog {
private static String NAOQI_IP = "10.0.1.236";
//public static String NAOQI_IP = "127.0.0.1";
private static int NAOQI_PORT = 9559;
static ALMemoryProxy memory = new ALMemoryProxy(NAOQI_IP, NAOQI_PORT);
static ALSpeechRecognitionProxy recog = new ALSpeechRecognitionProxy(NAOQI_IP, NAOQI_PORT);
static ALTextToSpeechProxy tts = new ALTextToSpeechProxy(NAOQI_IP, NAOQI_PORT);
public static void main(String[] args) {
String [] vocab = {"nao", "monkey", "hello"};
recog.unsubscribe("WordRecognized");
recog.setAudioExpression(true);
recog.setVisualExpression(true);
recog.setVocabulary(vocab, true);
recog.subscribe("WordRecognized");
while(true){
if(memory.getData("SpeechDetected").toBoolean()){
Variant words = memory.getData("WordRecognized");
String word = (String)words.getElement(0).toString();
System.out.println("The word is:" + word+":");
float percent = (float) words.getElement(1).toFloat();
for(int i = 0; i<words.getSize(); i+=2){
System.out.println("Word: " + (String)words.getElement(i).toString());
System.out.println("Probability: " + (float)words.getElement(i+1).toFloat());
}
//if(wordCheck())
//break;
if(!word.equals("") && percent > 0.2){
if(word.equals("nao")){
tts.say("How can I help you?");
System.out.println("how?");
break;
}
else if(word.equals("monkey")){
System.out.println("who you calling");
tts.say("who you callin a monkey?");
break;
}
else{
System.out.println("Not recognized");
}
}
}
}
recog.unsubscribe("WordRecognized");
System.out.println("done!");
}
}