CMUSphinx implements keyword definition in the pocketsphinx engine, see FAQ for details .
To recognize one key phrase, you can start the decoder in the "keyphrase" search mode.
From the command line try:
pocketsphinx_continuous -infile file.wav -keyphrase "oh mighty computer" -kws_threshold 1e-20
From the code:
ps_set_keyphrase(ps, "keyphrase_search", "oh mighty computer"); ps_set_search(ps, "keyphrase_search); ps_start_utt(); /* process data */
You can also find examples for Python and Android / Java in our sources. Python code looks like this: full example here :
# Process audio chunk by chunk. On keyphrase detected perform action and restart search decoder = Decoder(config) decoder.start_utt() while True: buf = stream.read(1024) if buf: decoder.process_raw(buf, False, False) else: break if decoder.hyp() != None: print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()]) print ("Detected keyphrase, restarting search") decoder.end_utt() decoder.start_utt()
A threshold must be configured for each passphrase on the test data in order to get the right balance of missed detectors and false alarms. You can try values ββfrom 1e-5 to 1e-50.
For best accuracy, it is better to have a passphrase with 3-4 syllables. Too short phrases are easily confused.
You can also search for several key phrases, create a keyphrase.list file as follows:
oh mighty computer /1e-40/ hello world /1e-30/ other_phrase /other_phrase_threshold/
And use it in the decoder with the -kws configuration parameter.
pocketsphinx_continuous -inmic yes -kws keyphrase_list
This feature is not yet implemented in the sphinx4 decoder.