I am currently trying to make my java code (using eclipse) perform some function if a certain thing is said. I am using the Sphinx4 libraries and this is what I currently have:
What I would like it to do is at the line where it says:
IF (TRUE) someFunction();
is to run the function if my speech is Hello Computer, Hello Jarvis, Good Morning Computer, or Good Morning Jarvis. Or in other words, run the function if the speech matches the "public < greet >" line of code in the .gram file. Even more specific, return "greet" if my speech corresponds with that grammar rule. I am sorry if this doesnt make sense...
Here is my listener.java file:
package speechRecognition;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
public class Listener {
public void someFunction(){
System.out.println("Did Something");
}
public static void main(String[] args) {
ConfigurationManager cm;
if (args.length > 0) { cm = new ConfigurationManager(args[0]);
} else { cm = new ConfigurationManager(Listener.class.getResource("configurations.config.xml")); }
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
while (true) {
Result result = recognizer.recognize();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
if (resultText != "" && resultText != null) {
IF (TRUE) someFunction();
}
} else {
System.out.println("I can't hear what you said.
");
}
}
}
}
And here is my dictionary.gram:
#JSGF V1.0;
grammar dictionary;
public <greet> = (Hello | Good Morning) (Jarvis | Computer);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…