Sphinx3 python quickstart

From Sphinx

Contents

Install Sphinx3 v. 0.7 trunk

See the Main Page for instructions on how do this.

NOTE: previous versions of sphinx3 do not come with Python interfaces.

Build/install python interface

In order to access sphinx3 from python, a .so file will be needed to be built and installed into Python site-packages. This can be done with the following steps.

$ su -
$ cd /path/to/sphinx3/python
$ python setup.py install

You may have to download the sourcecode for python (python -V to find which version) to location XXX.

Make sure XXX/Include/ is in the 'include_dirs' in setup.py.

I got 4 build errors, just added a last parameter , FALSE each time.

Verify/Load

In the Sphinx3 Speech Recognition Quick Start tutorial, you created a file called cfgfile. Please cd to that directory as we will be re-using the configuration file.

$ cd $DIR_DESCRIBED_ABOVE
$ python
>>> import _sphinx3

This should work without any error messages.

If you get a Python Import Error...

Initialize

>>> _sphinx3.parse_argfile("cfgfile")
>>> _sphinx3.init()

Decode

>>> data = open("pleaseaudio.raw").read()
>>> _sphinx3.decode_raw(data)

Output

...
FWDVIT: PLEASE (* 107 428Z131015)
... 

If it did not recognize, double check that the cfgfile has valid values. Retry Sphinx3 Speech Recognition Quick Start and make sure everything works when running under that context.

Lower-level API usage

Instead of using decode_raw(), slightly lower-level api's can be used. This is the way you would need to use it when dealing with streaming data, such as when using voip.

For this to work, you will actually need to hack _sphinx3module.c and make the following change

>>> _sphinx3.parse_argfile("cfgfile")
>>> _sphinx3.init() 
>>> _sphinx3.begin_utt()
>>> data = open("pleaseaudio.raw").read()
>>> _sphinx3.process_raw(data)
>>> _sphinx3.end_utt()
>>> hyp = _sphinx3.get_hypothesis()
>>> print hyp
related