현재 일기를 사용하여 내 Java 코드를 만들려고하고 있는데 특정 기능이 있다고 말하면 일부 기능을 수행하려고합니다. 나는 Sphinx4 라이브러리를 사용하고이 내가 현재 가지고있는 것입니다 : 안녕하세요Sphinx4로 키워드 또는 키 프레이즈 검색
IF (TRUE) someFunction();
내 음성 인 경우 기능을 실행하는 것입니다 :
내가 그것을 할 싶습니다 어떤 것은 말하는 줄입니다 컴퓨터, Hello Jarvis, Good Morning Computer 또는 Good Morning Jarvis. 또는 .gram이 .gram 파일의 "public < greet>"코드 줄과 일치하는 경우 함수를 실행하십시오. 더 구체적으로 말해서, 나의 연설이 그 문법 규칙과 일치하면 "인사"하라.
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.\n");
}
}
}
}
그리고 여기 내 dictionary.gram입니다 :
#JSGF V1.0;
grammar dictionary;
public <greet> = (Hello | Good Morning) (Jarvis | Computer);
를 참조하십시오이 키워드가 될 것이다, 문법의 한 부분에 대한 OutOfGrammarBranch을 할 수 있습니까? –