-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech.java
89 lines (78 loc) · 3.01 KB
/
speech.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Created by SAJAL TYAGI
22/12/2015
21:12 IST
*/
package com.sajal;
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 java.io.IOException;
public class speech {
public static void main(String[] args) throws IOException {
ConnectMail connectMail = new ConnectMail();
ConfigurationManager cm;
Process p = null;
int track = 0;
if (args.length > 0) {
cm = new ConfigurationManager(args[0]);
} else {
cm = new ConfigurationManager(speech.class.getResource("helloworld.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);
}
System.out.println("Say: (Open) ( Paint | Notepad | CMD)");
Runtime runtime = Runtime.getRuntime();
while (true) {
System.out.println("Start speaking. Press Ctrl-C to quit.\n");
Result result = recognizer.recognize();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
System.out.println("You said: " + resultText + '\n');
if (resultText.equals("paint") || resultText.equals("open paint")) {
if (track == 0) {
p = runtime.exec("mspaint");
track++;
}
}
if (resultText.equals("note") || resultText.equals("open note")) {
if (track == 0) {
p = runtime.exec("notepad");
track++;
}
}
if (resultText.equals("system")) {
if (track == 0) {
p = runtime.exec("cmd /c start cmd.exe");
track++;
}
}
if(resultText.equals("connect")){
if(track == 0){
connectMail.Gmail();
// track++;
}
}
if (resultText.equals("close") || resultText.equals("exit")) {
try {
if (track > 0) {
p.destroy();
track--;
}
} catch (NullPointerException n) {
System.err.println("ERROR :" + n);
}
}
} else {
System.out.println("I can't hear what you said.\n");
}
}
}
}