I found some examples how it is possible change pocketsphinx grammar in runtime using c code. But I could not achieved same thing using python. I was using trunk code and feature-vad branch.
In general I want to achieve dialog system using pocket sphinx written on java or python I am using home-brewed Lithuanian acoustic model. On each step there is different set of grammar that I need to use for recognition. I considered 3 approaches:
dictation with statistical language model,
different instance of pocketsphinx engine
different grammar switching for same engine.
I reject first as my acoustic model generates insufficient recognition results. I rejected 2nd as I found that there is some engine-worm-up period: for first ten or so recondition attempts engine does not recognize anything properly and after engine adapts and works acceptably.
So I chose to investigate 3rd approach switching grammars in each state of dialog.
I assume that fsg format is preferred over jsfg due performance reason and I transformed all files(see source code resource/*.fsg). After I reviewed swig provided APIs I found that fsg grammar could be changed using
But I could not found any swig API or hint how I could load grammar as instance of FsgModel object. Then in c code I found that there is fsg_model_readfile(...) for that. As this method is stateless I put in the most convenient place for me: ps_decoder.i diff for feature-vad branch
After swig I recompiled swig I could write method(see source code src/ContinuousPocketsphinx.py):
def updateGrammar(self,pDecoder, pGramma):
'''
Update decoder language model from fsg file
'''
logmath = pDecoder.get_logmath();
# read fsg file
fsg = pDecoder.readfile(os.path.join("../resource/", pGramma+'.fsg'), logmath)
# switch grammar for pocketshpinx engine
pDecoder.set_fsg("default",fsg);
pDecoder.set_search("default");
I tested this approach and it is working.
and at lass my questions: If switching grammar as I am doing is sufficient. If it is so could my patch be applied to main source code repository. If not how I should do replacement?
Last edit: mondhs 2014-02-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am writing here as my problem seems relevant to your solutions.
I have designed the model with sphinxtrain for controlling application in German with approximately 100 words. The recognition accuracy is very good when we say the complete commands and also the words used randomly , but whenever we say something else other than the words used (for example in english), its printing something , also sometimes with the complete commands it is printing something else in extra. How can i optimize it ! Can you kindly suggest..
If possible send me some reference links .. Thank you!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I found some examples how it is possible change pocketsphinx grammar in runtime using c code. But I could not achieved same thing using python. I was using trunk code and feature-vad branch.
In general I want to achieve dialog system using pocket sphinx written on java or python I am using home-brewed Lithuanian acoustic model. On each step there is different set of grammar that I need to use for recognition. I considered 3 approaches:
I reject first as my acoustic model generates insufficient recognition results. I rejected 2nd as I found that there is some engine-worm-up period: for first ten or so recondition attempts engine does not recognize anything properly and after engine adapts and works acceptably.
So I chose to investigate 3rd approach switching grammars in each state of dialog.
After digging. I came up with solution that I would like confirm. Full source code: https://github.com/mondhs/lt-pocketsphinx-tutorial/blob/master/impl/demo-py/public_service/
I assume that fsg format is preferred over jsfg due performance reason and I transformed all files(see source code resource/*.fsg). After I reviewed swig provided APIs I found that fsg grammar could be changed using
But I could not found any swig API or hint how I could load grammar as instance of FsgModel object. Then in c code I found that there is fsg_model_readfile(...) for that. As this method is stateless I put in the most convenient place for me: ps_decoder.i diff for feature-vad branch
After swig I recompiled swig I could write method(see source code src/ContinuousPocketsphinx.py):
I tested this approach and it is working.
and at lass my questions: If switching grammar as I am doing is sufficient. If it is so could my patch be applied to main source code repository. If not how I should do replacement?
Last edit: mondhs 2014-02-28
Thank your for contribution. I added it as a second construction, so you call it as
Hello.
I am writing here as my problem seems relevant to your solutions.
I have designed the model with sphinxtrain for controlling application in German with approximately 100 words. The recognition accuracy is very good when we say the complete commands and also the words used randomly , but whenever we say something else other than the words used (for example in english), its printing something , also sometimes with the complete commands it is printing something else in extra. How can i optimize it ! Can you kindly suggest..
If possible send me some reference links .. Thank you!!