Skip to content

Demo: Jsgf grammar mode

Pankaj Baranwal edited this page Oct 11, 2017 · 1 revision

Grammars describe very simple type of the language for command and control, and they are usually written by hand or generated automatically within the code. Grammars usually do not have probabilities for word sequences, but some elements might be weighed. Grammars could be created with JSGF format and usually have extension like .gram or .jsgf.

To test jsgf grammar mode, use the launch file asr.launch with the following command:

roslaunch pocketsphinx asr.launch input:=/home/<your_user_name>/catkin_ws/src/pocketsphinx/demo/goforward.raw dict:=/home/<your_user_name>/catkin_ws/src/pocketsphinx/demo/turtle.dic gram:=/home/<your_user_name>/catkin_ws/src/pocketsphinx/demo/goforward rule:=move2 grammar:=my_grammar

This will publish a topic grammar_data which publishes the detected statements.
The output of this launch file can be viewed using the following command in a new terminal window:

rostopic echo /grammar_data

If instead of using an audio file as input, you require to use your system's microphone, just remove the input parameter from the above command:

roslaunch pocketsphinx asr.launch dict:=/home/<your_user_name>/catkin_ws/src/pocketsphinx/demo/turtle.dic gram:=/home/<your_user_name>/catkin_ws/src/pocketsphinx/demo/goforward rule:=move2 grammar:=my_grammar

There are two modes which can be employed using this same launch file:

Grammar Mode
Grammars describe a very simple type of the language for command and control. Grammars allow you to specify possible inputs very precisely, for example, that a certain word might be repeated only two or three times.

Language Model
Statistical language models describe more complex language. They contain probabilities of the words and word combinations. Those probabilities are estimated from sample data and automatically have some flexibility. For example, every combination from the vocabulary is possible, though probability of each combination will vary.

Following are the arguments which can be used when launching this particular launch file:
dict
Location(absolute path) of the dictionary. Dictionary contains the words which are used in the keyphrases along with their phonetics as used in the acoustic model.

gram
Absolute path of the gram file containing your grammar. To know more about how to prepare jsgf grammar, please read the section on text preparation in the Cmusphinx docs.

grammar
The name of the grammar used.

rule
Which rule is to be employed. Rules are described within a grammar.

lm
In case you want to use language model instead of grammar mode, you will omit the three arguments mentioned above(gram, grammar, rule) and specify this argument instead. Its value will contain a .lm file. Please read the section on language models within the CMUSphinx docs to know more.

input
If you want to use an audio file as input, you can specify its absolute path here. Else you should omit this argument. System's microphone will be used as input instead.

hmm
In case the default acoustic model is missing or not suited to your needs, you can specify a new one using this argument. Just add its absolute path as value of this argument. You can find the existing ones here.

Clone this wiki locally