-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathVoice_asistant.java
40 lines (28 loc) · 1.14 KB
/
Voice_asistant.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
import java.io.IOException;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult;
public class VoiceAssistant {
public static void main(String[] st) {
Configuration config = new Configuration();
config.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
config.setDictionaryPath("src\\main\\resources\\5057.dic");
config.setLanguageModelPath("src\\main\\resources\\5057.lm");
try {
LiveSpeechRecognizer speech = new LiveSpeechRecognizer(config);
speech.startRecognition(true);
SpeechResult speechResult = null;
while ((speechResult = speech.getResult()) != null) {
String voiceCommand = speechResult.getHypothesis();
System.out.println("Voice Command is " + voiceCommand);
if (voiceCommand.equalsIgnoreCase("Open Chrome")) {
Runtime.getRuntime().exec("cmd.exe /c start chrome www.infybuzz.com");
} else if (voiceCommand.equalsIgnoreCase("Close Chrome")) {
Runtime.getRuntime().exec("cmd.exe /c TASKKILL /IM chrome.exe");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}