How to Create your own Voice Assistant using Java ?

In this article we will see how to create our own Voice Assistant using Java ?
You might have used Google Assistant, Siri OR Amazon Alexa. So that kind of voice assistant we are going to create in Java using Sphinx library. In other words you can say that how to make a voice assistant in java ?

Let's start by adding Sphinx dependencies in our pom.xml file.



Now let's have our own voice assistant to open Google Chrome browser and to close Google Chrome browser. First you need to go to Sphinx Knowledge Base Tool and provide your commands and download dictionary and language model file. That's what you need to pass while doing configuration.


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();
		try {
			LiveSpeechRecognizer speech = new LiveSpeechRecognizer(config);
			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");
				} else if (voiceCommand.equalsIgnoreCase("Close Chrome")) {
					Runtime.getRuntime().exec("cmd.exe /c TASKKILL /IM chrome.exe");
		} catch (IOException e) {