-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphnix4.java
More file actions
54 lines (36 loc) · 1.33 KB
/
Sphnix4.java
File metadata and controls
54 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package robot.robonce;
import java.io.IOException;
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;
import edu.cmu.sphinx.util.props.PropertyException;
public class Sphnix4 {
//ATributos:
ConfigurationManager cm;
Recognizer recognizer;
//Constructores:
public Sphnix4 () throws IOException, PropertyException, InstantiationException{
cm = new ConfigurationManager(Navegar.class.getResource("voice.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
// start the microphone or exit if the program if this is not possible
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
recognizer.deallocate();
System.exit(1);
}
}
//Metodos:
public String listen (){
String resultText = "";
Result result = recognizer.recognize();
if (result != null) {
resultText = result.getBestFinalResultNoFiller();
}else {
System.out.println("I can't hear what you said.\n");
}
return resultText;
}
}