import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
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 CislaHandler implements RocnikacHandler {
private ConfigurationManager cm;
private Recognizer recognizer;
private Microphone microphone;
Result result = null;
while ((result = recognizer.recognize()) != null) {
if (result != null) {
String resultText = result.
getBestResultNoFiller();
res += resultText;
}
}
return res;
}
public boolean LoadFirstRequest
(String fileName
) { try {
url =
new File(fileName
).
toURI().
toURL();
// TODO Auto-generated catch block
e.printStackTrace();
}
cm = new ConfigurationManager(url);
// allocate the recognizer
recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
System.
out.
println("Recognizer ok");
// start the microphone
microphone = (Microphone) cm.lookup("microphone");
//microphone.startRecording();
System.
out.
println("Microphone ok");
return true;
}
public boolean LoadRequest
(String fileName
) { recognizer.deallocate();
try {
url =
new File(fileName
).
toURI().
toURL();
// TODO Auto-generated catch block
e.printStackTrace();
}
cm = new ConfigurationManager(url);
// allocate the recognizer
recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
System.
out.
println("Recognizer ok");
// start the microphone
microphone = (Microphone) cm.lookup("microphone");
//microphone.startRecording();
System.
out.
println("Microphone ok");
return true;
}
public boolean QuitRequest() {
// TODO Auto-generated method stub
return true;
}
public boolean StartRequest() {
microphone.startRecording();
return true;
}
public boolean StopRequest() {
microphone.stopRecording();
return true;
}
public boolean Initialize() {
/*
URL url;
url = RocnikacSphinxWrapper.class.getResource("RocnikacSphinxWrapper.config.xml");
cm = new ConfigurationManager(url);
// allocate the recognizer
recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
System.out.println("Recognizer ok");
// start the microphone
microphone = (Microphone) cm.lookup("microphone");
//microphone.startRecording();
System.out.println("Microphone ok");
// TODO Auto-generated method stub*/
return true;
}
}