Mindfire Solutions
Home  |  Faq  |  Site map  |  Contact
Email sales@ or Call 1-248-686-1424
news
Share | Share on Facebook Share on Twitter Share On Linkedin
Speech Recognition using Sphinx4 in Java
Author: Milan Chandna

What is Speech Recognition? 

Speech Recognition means recognizing the speech and converting it into readable form (text).
With the help of speech recognition we can take the user voice as input (dynamically), convert it into text and use it to perform various functions in our program.

Requirements

For speech recognition you need following packages
 
-- Sphinx4 src is available on internet [src means source version to build the programs]
-- Apache ANT to build the sphinx and your program.
 
Sphinx4 is a set of classes which further use Java Speech API (jsapi) as Speech Recognition Engine.
Sphinx provides already build Acoustic Models, Language Models, Dictionary and JSPAI
Sphinx also provides some demo examples to test the working and these demo examples can then be modified according to our use.
These demo examples can be found in directory "sphinx4\src\apps\edu\cmu\sphinx\demo\"
ConfigurationManager cm;
cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));
Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();
 
// start the microphone or exit if the programm if this is not possible
Microphone microphone = (Microphone) cm.lookup("microphone");
if (!microphone.startRecording())
{
     recognizer.deallocate();
     System.exit(1);
}
while (true)
{
 
   Result result = recognizer.recognize();
   if (result != null)
   {
       String resultText = result.getBestFinalResultNoFiller();
       // You will get the spoken word in "resultText" as a String
    // Use this string and write your code according to your requirments
   }
 }
}
****************/
Rest of the code like creating GUI can be created according to the requirements
 
 
Given Grammar file can also be modified according to your choice of words to be recognized
 
Then to build this program install Apache Ant  (unzip the Apache Ant freely available on internet in any directory)
Set enviroment variables as 
CLASSPATH : "apache ant bin directory's path"; "java bin directory's path"
ANT HOME : "apache ant directory's path"
JAVA HOME : "java directory's path"
 
Open command prompt and go to sphinx directory
enter Command : ANT 
This will build the whole sphinx and jar file of your program can be seen in BIN folder of Sphinx directory

How to use

This jar file has to be run using command prompt
open command prompt and go to sphinx directory
write command : java -mx312m -jar bin\HelloWorld.jar
this command will run your program
 
If you want to send this jar to someone then you would have to give her/him the library files. Library files used by the program can be found in the manifest file inside HelloWorld.jar 
Files mentioned under CLASSPATH in this manifest file are used as libraries
You can find these library jar files in lib folder of sphinx directory
Copy these files pack them in folder named 'lib' and package it with your HelloWorld.jar
 

LOOPHOLES :

1. before building make sure that you extract JSAPI.JAR out of jsapi.exe in LIB directory of sphinx
2. if you have already build the the program once and you want to modify GRAMMAR file or CONFIG.XML file, you have to write command : ant clean
and then again write command : ant..........otherwise it wont accept the change in GRAMMAR file or XML file.

Related Tags:
Java,Speech Recognition, JSAPI, ANT, Sphinx4

top