Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, December 16, 2013

rrdtool create using python in Ubuntu 10.04 raises "TypeError: argument 3 must be string"

I was trying example 2 from this page: http://oss.oetiker.ch/rrdtool/prog/rrdpython.en.html#___top

It was working perfectly for me in Ubuntu12.04 but when I tried to port my code to Ubuntu 10.04, I got the following error:
Traceback (most recent call last):
  File "test.py.orig", line 14, in
    'RRA:AVERAGE:0.5:6:10' )
TypeError: argument 5 must be string


Wasted a lot of time trying to solve it before this finally worked:
rrdtool.create( 'speed.rrd',
              '--start', '920804400',
      '-s', '60',
              'DS:speed1:COUNTER:600:U:U',
              'DS:speed2:COUNTER:600:U:U',
              'DS:speed3:COUNTER:600:U:U',
              'RRA:AVERAGE:0.5:1:24',
              'RRA:AVERAGE:0.5:6:10' )

Hopefully, it saves someone a bit of time

Saturday, December 15, 2012

Getting PocketSphinx working

I read a lot of how-to's on how to get pocketsphinx functional on Ubuntu 10.04 but I always got stuck at some point.
These are the two failures I could never get around: 
1. Failed to open audio device(/dev/dsp): No such file or directory


2. ERROR: "acmod.c", line 88: Must specify -mdef or -hmm

After a lot of trying different things out, here are the steps that allowed me to get a raw file transcribed.

aptitude install python-pocketsphinx
aptitude install pocketsphinx-hmm-wsj1
aptitude install pocketsphinx-lm-wsj

The ps_test.py file will be located in /usr/share/doc/python-pocketsphinx/examples
Change the first line to
decoder = ps.Decoder(hmm="/usr/share/pocketsphinx/model/hmm/wsj1",
                    lm="/usr/share/pocketsphinx/model/lm/wsj/wlist5o.3e-7.vp.tg.lm.DMP",
                    dict="/usr/share/pocketsphinx/model/lm/wsj/wlist5o.dic",
                    fwdtree="yes",
                    fwdflat="yes",
                    bestpath="no")

Change line 2 to:
fh = open("test.raw", "rb")


And generate a test.raw file and put it in /usr/share/doc/python-pocketsphinx/examples

Running python ps_test.py will still generate an error but you should get a first transcription:


Decoded 35136 samples
THE DEMAND JUMPED OVER THE MILAN (000000000 -40091455)
P(FORWARD|GO) = -4.346504, 2
INFO: ngram_search.c(1046): lattice start node .0 end node .207
INFO: ps_lattice.c(1225): Normalizer P(O) = alpha(
:207:218) = -2837676
INFO: ps_lattice.c(1263): Joint P(O,S) = -2853722 P(S|O) = -16046
P(S|O) = -1.604786e+00
FORWARD is:
Traceback (most recent call last):
  File "ps_test.py", line 30, in
    print "FORWARD is:", forward.word, forward.sf, forward.fef, forward.lef, forward.prob
NameError: name 'forward' is not defined


My raw file had the phrase 'The man jumped over the moon'
It was transcribed to 'THE DEMAND JUMPED OVER THE MILAN'


Changing hmm to hub4opensrc.cd_continuous_8gau, lm to language_model.arpaformat.DMP and adding the word MOON to the dictionary got me to the following transcription: 'THE MEN JUMPED OVER THE MOON'

Not bad, IMHO
  • Book reviews