demo code for voice assistant in java

Solutions on MaxInterview for demo code for voice assistant in java by the best coders in the world

showing results for - "demo code for voice assistant in java"
Alice
26 Mar 2017
1import java.io.IOException;
2
3import edu.cmu.sphinx.api.Configuration;
4import edu.cmu.sphinx.api.LiveSpeechRecognizer;
5import edu.cmu.sphinx.api.SpeechResult;
6
7public class VoiceAssistant {
8
9	public static void main(String[] st) {
10		
11		Configuration config = new Configuration();
12		
13		config.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
14		config.setDictionaryPath("src\\main\\resources\\5057.dic");
15		config.setLanguageModelPath("src\\main\\resources\\5057.lm");
16		
17		try {
18			LiveSpeechRecognizer speech = new LiveSpeechRecognizer(config);
19			speech.startRecognition(true);
20			
21			SpeechResult speechResult = null;
22			
23			while ((speechResult = speech.getResult()) != null) {
24				String voiceCommand = speechResult.getHypothesis();
25				System.out.println("Voice Command is " + voiceCommand);
26				
27				if (voiceCommand.equalsIgnoreCase("Open Chrome")) {
28					Runtime.getRuntime().exec("cmd.exe /c start chrome www.infybuzz.com");
29				} else if (voiceCommand.equalsIgnoreCase("Close Chrome")) {
30					Runtime.getRuntime().exec("cmd.exe /c TASKKILL /IM chrome.exe");
31				}
32				
33			}
34			
35		} catch (IOException e) {
36			e.printStackTrace();
37		}
38		
39	}
40}
41
similar questions
queries leading to this page
demo code for voice assistant in java