This is a crisp post on playing with the Open Source Speech Recognition Toolkit – PocketSphinx by Carnegie Mellon University.
We need to install the sphinx packages before we can proceed with it:
- python-pocketsphinx
- pocketsphinx-hmm-wsj1
- pocketsphinx-lm-wsj
The packages can be installed from Ubuntu Software center or via apt-get.
$ sudo apt-get install python-pocketsphinx $ sudo apt-get install pocketsphinx-hmm-wsj1 $ sudo apt-get install pocketsphinx-lm-wsj
Once you are done we can move on with out python script for speech recognition.
Have a voice recorded WAV file in the directory where you are running the python script. You can record voice by your fav voice recorder software.
Script: pythonPocketSphinxTest.py
#!/usr/bin/ python import sys import pocketsphinx if __name__ == "__main__": hmdir = "/usr/share/pocketsphinx/model/hmm/wsj1" lmdir = "/usr/share/pocketsphinx/model/lm/wsj/wlist5o.3e-7.vp.tg.lm.DMP" dictd = "/usr/share/pocketsphinx/model/lm/wsj/wlist5o.dic" wavfile = sys.argv[1] speechRec = pocketsphinx.Decoder(hmm = hmdir, lm = lmdir, dict = dictd) wavFile = file(wavfile,'rb') speechRec.decode_raw(wavFile) result = speechRec.get_hyp() print result
Execute:
$ python pythonPocketSphinxTest.py sndClip.wav
Note: sndClip.wav is my voice recorded file, and lies in the same folder as the script pythonPocketSphinxTest.
Output:
'LITTLE WHO FALLS MORE IN THE IN THE FULL AND WHO IS NEWS UNLIKE TO THE USE THAN THIS SO ALL HER WHOSE'
This code is working well for files which are less than 30 secs.
Is there a way where i can accomplish the task for files which are more than
30 seconds?
Thanks in advance
When i installed pocketsphinx-hmm-wsj1 and pocketsphinx-lm-wsj, the error message comes like
E: Unable to locate package pocketsphinx-hmm-wsj1
E: Unable to locate package pocketsphinx-lm-wsj
Can anybody give the solution??
# It should work from source
# dependencies:
$ sudo apt-get install -qq python python-dev python-pip build-essential swig git libpulse-dev
# sources
$ git clone –recursive https://github.com/bambocher/pocketsphinx-python
# install
$ sudo python pocketsphinx-python/setup.py install