Java Speech Development Kit: A Tutorial

The authors show how to get started developing voice-activated interfaces using the Speech for Java Development Kit.

The voice recognition is based upon a set of words (phonemes) named grammars. A created recognizer can have associated grammars, increasing its recognition domain according to the application needs. Having associated grammars, the recognizers generate result objects as answers to the recognition process. These results contain information about what was understood. This information is made available through ResultEvents fired by the results and caught by ResultListener, where the implementation determines what to do with the recognized data.

To implement this schema the recognizer can have two types of associated grammars, each one of them with its own word domain. They have distinct size and elements and determine a different recognition process:

  • Dictation grammars: these grammars are comprised of sets of words with thousands of elements. Their elements are determined by the function of their comprised domain, such as medicine, computer science or engineering. A general purpose grammar is available with the development kit.

    Dictation grammars analyze the context of what is being spoken and try to limit the set of words that can be said next. Their use is specific to continuous dictating speech, such as texts and sentences. Great processing capacity is needed, therefore, and its use requires well projected applications.

    The creation of a dictation grammar is done through a recognizer that supports its use. It is illustrated in here:

                 DictationGrammar dictationGrammar =
  • Rule grammars: these are simpler than dictation grammars. They are comprised of rules that determine what can be said and how it will be represented inside the application. The rules are defined in a special format named JSGF (Java Speech Grammar Format) and can be loaded one at a time or many at once during execution.

    Rule grammars require less processing capacity than dictation grammars and its recognition accuracy is much higher, resulting in a bigger number of accepted results. This is possible because of their limited scope of recognition. It is a grammar well suited for voice-command definitions, determining a specific set of commands for the various contexts of an application.

There are two ways to create a rule grammar:

  • through the loadJSGF method, when a set of rules is loaded from a text file; or

  • through the newRuleGrammar method, which returns an empty rule grammar that must be specified during execution.

Example Code

Both methods belong to the recognizer interface, being the grammar automatically associated with the recognizer that created it.

Java Speech Grammar Format

The speech recognition systems make it possible for the computer to hear what a user says and "understand" what was spoken. Speech for Java does not yet support speech recognition without restrictions; the ability to hear any speech in any context and understand it accurately. To reach a reasonable accuracy and answer time, the recognition limits what might be said through the use of grammars, as seen in the previous section. The Java Speech Grammar Format (JSGF) language defines a way to describe what is named as a RuleGrammar. It uses a textual representation that might be read and edited by both developers and users through a simple text editor.

The rules have the following structure:

Figure 3. JSGF Rule Structure

If something is said and the recognition is not above a confidence level--defined through the use of the method setConfidenceLevel (the default is de 0.5)--a resultRejected rejection event will be triggered. Otherwise a resultAccepted event is created, and the method getTags returns the identifier(s) of the correspondent rule. Table 3 shows the main JSGF features:

Table 3. Main Uses of the JSGF Language




What Might Be Said

Simple words


<rule1> = open {open};


Whole phrases


<rule2> = open the program {open};

"open the program"

Multiple choices


<rule3> = open| open the program {open};

"open" or "open the program"

Optional words


<rule5> = [please] open {open};

"open" or "please open"

Rule referencing


<rule6> = <regra5> {open};

The same as rule 5

Enclosing operator *


<rule7> = 13579* times;

"1", "3", "5", "7", "9", "11", "13", "99", "93", or another number (including none) formed by 1, 3, 5, 7 and 9 in any order followed by times

Enclosing operator +


<rule8> = 13579+ times;

This time a number must be said following the pattern seen in rule7

Here is an example illustrating the use of this technique.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Reference Links are Dead

Gobinath's picture

hi there
this is a very nice article. i really liked it and i planned to implement this in my project but unfortunately all the references links are dead.

kindly help me out . u can reach me at

any help will be of great help..


Reference Links are Dead

Gobinath's picture

hi there
this is a very nice article. i really liked it and i planned to implement this in my project but unfortunately all the references links are dead.

kindly help me out . u can reach me at

any help will be of great help..


This is really useful. I

siva's picture

This is really useful. I successfully completed my project voice controlled wheel chair with the help of this concept... It works well....

Re: Java Speech Development Kit: A Tutorial

Anonymous's picture

Is there lib to use text to speak in portuguese language ?

Re: Java Speech Development Kit: A Tutorial

Anonymous's picture

i have read your tutorial about the Java Speech Development Kit, it is truely very interesting, i would realy love to develop a programe of my own on this context. please help me im a graduate from the University of Botswana in Computer Science in Botswana, i realy ineterested in speech program but i dont know where to start and what i need. more especialy that i dont have any of the classies that i can use for statup training plz give me an advice.

my Email is

thank you in advace

Moathodi Excellent Matikiti

Re: Java Speech Development Kit: A Tutorial

Anonymous's picture

I am in the same situation as Moathodi, were I would like to develope a program on this subject. I would really appreciate it if you could aid me in kicking it of as I am not sure were to start.

My email is

Many Thanks


Speech recognition engines

Mario's picture

I have done a lot of research on the speech development architecture of java..but i am more interested in some package that might make the development of a speech to text application faster. Thanx...hope i get a emaill is

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up and watch now

Sponsored by Skybot