Speech Recognition Library for java

Hi,
     We have seen Google's Assistant and IOS's siri and JARVIS etc. these AIs' are not single functionality to achieve easily. we need to recognize speech and act based on that and speaking text to out. So many things needed to achieve these.
   
      In that Taking input from user also major role i.e Speech Recognition

     So this post is showing how to code Speech recognition in java, i have searched many sites to find the library for this. finally i found Sphinx4 library for java which is open source.
     i couldn't wait to implement this, so started coding. if your not going in-depth its all about few lines of code to recognize your voice. i just want to show the code as simple as possible.
     Previous version of Sphinx we used to write dictionary to recognize. In '.gram' file we were giving words to recognize these called voice tokens.
    But now we have tokens ready with Sphinx so we give it to Configuration Object. so we are good to go with just few lines of code that is given below.
   Hope this post will help, please give me feedback.

Assuming Maven project.
Dependencies needed for the project
pom.xml
 <dependencies>
<dependency>
  <groupId>edu.cmu.sphinx</groupId>
  <artifactId>sphinx4-core</artifactId>
  <version>5prealpha-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>edu.cmu.sphinx</groupId>
  <artifactId>sphinx4-data</artifactId>
  <version>5prealpha-SNAPSHOT</version>
</dependency>
 </dependencies>
<repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

ListenToVoice.java
public class ListenToVoice {

public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();

conf.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
conf.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
conf.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");

LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(conf);
recognizer.startRecognition(true);
System.out.println("start speaking:");
SpeechResult result = recognizer.getResult();
recognizer.stopRecognition();
System.out.println("result:"+result.getHypothesis());
}

}

Comments

Popular posts from this blog

Small virus code to hang your friend's system

How to use Remote Desktop