Menu

Building Pocket sphinx in uCLinux

Help
2012-07-19
2012-09-22
  • Josh Herrmann

    Josh Herrmann - 2012-07-19

    I am attempting to build pocket sphinx 0.7 in uCLinux running on a Blackfin
    BF548. I have browsed the instructions for building pocket sphinx on a
    standard distro of Linux i.e. Ubuntu/Debian and have been successful. However,
    I cannot find instructions to build on a limited version of Linux, namely
    uCLinux. Attempting to run the ./configure for sphinx base returns an issue
    with specifying the build type, for which I cannot overcome. Any assistance
    would be appreciated.

     
  • Josh Herrmann

    Josh Herrmann - 2012-07-21

    Okay, thanks for the info for the cross compiling. I have managed to progress
    further, but have encountered a problem, as I will explain shortly. Here's
    what I've done so far:

    1) Extracted sphinxbase and pocketsphinx archives
    2) ran ./configure --host=bfin-uclinux in sphinxbase folder
    3) ran "make" in sphinxbase folder
    4) ran ./configure --host=bfin-uclinux in pocketsphinx folder
    5) ran "make" in pocketsphinx folder

    At this stage, it appears that pocketsphinx was successfully cross-compiled
    for the correct target (blackfin running ucLinux). The thing is, I wasn't sure
    whether to run the final command for each program: "make install". I know that
    this would normally install pocketsphinx onto linux, and put sphinx library
    files and binaries in folders such as /usr/local/lib and /usr/local/bin. These
    folders don't exist on ucLinux, however.

    6) compressed both sphinxbase and pocketsphinx folders into .tar.gz archives
    (maintaining the compiled state of each program)
    7) transferred both archive files across to the blackfin
    8) extracted both files into their corresponding folders
    9) navigated to pocketsphinx/src/programs and ran "./pocketsphinx_continuous"

    The program starts, but immediately after parsing the command line,
    pocketsphinx shows an info message saying:

    pocketsphinx.c(104): Will not use mmap() on uClinux/Blackfin.INFO:
    feat.c(684): Initializing feature stream to type: '1s_c_d_dd', ceplen=13,
    CMN='current', VARNORM='no', AGC='none'

    Then, right below this, an error is thrown which says: ERROR: "acmod.c", line
    84: Acoustic model definition is not specified neither with -mdef option nor
    with -hmm.

    I suspect this is coming up either because: the sphinx libraries are not in
    the right place, so pocketsphinx_continuous cannot find them, there are
    missing audio libraries to allow pocketsphinx to detect the audio hardware, or
    possibly another problem exists.

    The question is, do I need to cross-compile pocketsphinx in such a way that I
    still run "make install"? Also, once pocketsphinx has been transferred across
    to the blackfin, how do I run it correctly?

     
  • Nickolay V. Shmyrev

    I suspect this is coming up either because: the sphinx libraries are not in
    the right place, so pocketsphinx_continuous cannot find them, there are
    missing audio libraries to allow pocketsphinx to detect the audio hardware, or
    possibly another problem exists.

    No, the reason is that in cross-compilation mode the location of the data
    files is not determined automatically. You need to point the binary with the
    path of the acoustic model using -hmm option, language model with -lm option
    and dictionary with -dict option

    The question is, do I need to cross-compile pocketsphinx in such a way that
    I still run "make install"? Also, once pocketsphinx has been transferred
    across to the blackfin, how do I run it correctly?

    You need to run make install. make install should install the binaries to some
    folder first. This folder is specified with DESTDIR variable during make
    install:

    make install DESTDIR=/path/to/device/root/fs/on/your/host/fs
    

    Then you should transfer the binary file to the device filesystem. In many
    distributions this process is automated. Blackfin uses buildroot which already
    integrate dozen of automake-based libraries. You can check how other libraries
    are built with buildroot and do the same. You can even create a new buildroot
    package for pocketsphinx and sphinxbase.

     
  • Josh Herrmann

    Josh Herrmann - 2012-07-24

    OK, so I have managed to successfully install both sphinxbase and
    pocketsphinx, as per your instructions:

    make install DESTDIR=/path/to/device/root/fs/on/your/host/fs

    , so thanks for that.

    However, I am now having trouble running pocketsphinx on the Blackfin. I tried
    specifying the language and acoustic models as well as the dictionary, but I
    realised that I didn't know which files to specify. I found some model looking
    files inside a couple of directories called "hmm" and "lm", but I wasn't sure
    which files in there to specify.

    So where can I find the right files to specify?

    One other thing: you mentioned to install pocketsphinx using

    make install DESTDIR=/path/to/device/root/fs/on/your/host/fs

    I did that, but the thing is, I don't have access to the device file system
    because it is not available under the host operating system, UNLESS I use
    buildroot and access the "temporary" device filesystem inside the buildroot
    directory. I assume that doesn't matter at the moment, but once I get
    buildroot going, I could probably send the pocketsphinx binaries to the right
    place.

     
  • Nickolay V. Shmyrev

    So where can I find the right files to specify?

    The right files to specify are in model folder in pocketsphinx distribution:

    -hmm model/hmm/en_US/hub4wsj_sc_8k
    -lm model/lm/en_US/hub4.5000.DMP
    -dict model/lm/en_US/ cmu07a.dic
    

    I don't have access to the device file system because it is not available
    under the host operating system

    When you create a filesystem image you have a folder where all the files are
    located. This folder is packed as a root filesystem on device during the
    build. Anyway, it's not a rocket science to arrange the files properly, I
    assume.

     
  • Josh Herrmann

    Josh Herrmann - 2012-07-25

    Right,

    Pocketsphinx now runs when I specify the model/dictionary files like you
    suggested, but just before the voice recognition part starts is an error:
    FATAL_ERROR: "continuous.c", line 242: Failed top open audio device.

    Now, when I first ran pocketsphinx in a non-embedded version of Linux (Linux
    Mint 12), I had the same error. To fix it, I installed a library called the
    "alsa development package" (correct name might be "libalsa2-dev" or
    something).

    Therefore, I assume that, if I was able to install the same library in
    ucLinux, then Pocketsphinx would work. Thing is, I haven't found a
    library/package with that name in the kernel configuration settings. There are
    some other packages which might be related: alsa-lib and libaudio. There is
    also a thing called "libsphinxbase".

    Which library/libraries do I need to add to the kernel to get pocketsphinx to
    run?

    Interestingly, in the kernel settings, alsa-lib isn't available because "alsa-
    lib requires FDPIC ELF support", or something like that. I found the kernel
    settings for "executable file formats" and FDPIC ELF, flat, and ZFLAT support
    is turned on.

    In the kernel/library support there is a menu called "blackfin build options"
    and in there the binary format can be changed to FDPIC. However when I made
    this change and tried to compile the kernel, it failed with two errors but no
    explanation as to what happened. Here:

    make: Leaving directory /home/blackfin/Development/blackfin/blackfin-linux- dist/lib' make: *** Error 2 make: Leaving directory/home/blackfin/Development/blackfin/blackfin-linux-
    dist/lib'
    make: *** Error 1

    So, what should I do about the libraries, and if I need to install alsa-lib,
    how do I do it without getting that error from changing to FDPIC ELF support?

     
  • Josh Herrmann

    Josh Herrmann - 2012-07-29

    Can anyone help me with the above issue?

     
  • Nickolay V. Shmyrev

    In Linux you can process sound through several subsystems. One of them is OSS
    another is ALSA. In desktop linux alsa is frequently used, in embedded systems
    it all depends on a driver availabilty. I don't think your blackfin board has
    alsa driver, though it might be the case. OSS subsystem is easier to setup.

    In order to fix your problem you need to:

    1. Find out which driver is supported

    2. Make sure that driver is enabled in kernel configuration:

    http://docs.blackfin.uclinux.org/doku.php?id=hw:cards:ad73311

    1. Make sure that userspace is properly configured for the required subsystem. In particular, the device files must be created (/dev/dsp for OSS and /dev/snd/* for ALSA)

    2. Make sure you can record audio with the corresponding subsystem tools (arecord or cat)

    It's easier to configure OSS subsystem, so you are recommended to stick with
    it. All you need to do is to check that you create /dev/dsp device with a
    proper major / minor numbers. You can get more details on device files in any
    book on the embedded development or in a manual for "mknod" command.

    Once you have /dev/dsp and OSS driver is enabled in kernel configuration
    together with OSS subsystem pocketsphinx with default build should be able to
    record audio from it.

    make: Leaving directory /home/blackfin/Development/blackfin/blackfin-linux- dist/lib' make: *** Error 2 make: Leaving directory/home/blackfin/Development/blackfin/blackfin-linux-dist/lib' make: *** Error
    1

    When you report about issues learn to provide the full log, not just few lines
    of it. The reason of this error is mentioned few lines above the last line you
    posted. You just need to read the log carefully.

     
  • Josh Herrmann

    Josh Herrmann - 2012-08-09

    Right, so I followed the directions on this page:
    http://docs.blackfin.uclinux.org/doku.php?id=linux-
    kernel:drivers:ad1980&s
    =ad1980, but I cannot, cannot, get the audio device to
    appear as a soundcard in the boot sequence. The audio device is definitely
    the AD1980, which is now discontinued according to this forum:
    http://blackfin.uclinux.org/gf/project/uclinux-dist/forum/?_forum_action=Foru
    mMessageBrowse&thread_id=45516&action=ForumBrowse
    .

    So, right now, I am unable to do anything with the audio. I didn't try and
    create the /dev/dsp or /dev/snd files, because I wanted to first know whether
    uCLinux could detect the AD1980 first.

    I can only assume, that if the audio device drivers were correctly installed,
    then I would see this at bootup:
    Advanced Linux Sound Architecture Driver Version 1.0.12rc1 (Thu Jun 22
    13:55:50 2006 UTC).
    ASoC version 0.13.2
    dma rx:0 tx:1, err irq:10, regs:ffc00800
    AD1980 SoC Audio Codec
    asoc: AC97 <-> bf5xx-ac97 mapping ok
    ALSA device list:

    0: bf5xx-board (AD1980)

    But I don't. I only see this:
    Advanced Linux Sound Architecture Driver Version 1.0.12rc1 (Thu Jun 22
    13:55:50 2006 UTC).

    Or a variant of.

    Finally, in regards to the log message I showed last time, I have managed to
    fix the issue, and now I can compile the kernel in FDPIC mode (because I
    disabled the pngview library). Thus I have managed to integrate the ALSA lib
    library into the kernel, but that hasn't fixed the issue of uCLinux not
    detecting the audio device.

    So how should I proceed from here?

     
  • Nickolay V. Shmyrev

    Well, this is offtopic here

    First of all check if driver module is loaded, not just alsa framework. Maybe
    you need to run one more modprobe.

    All linux drivers look for pci ids for the automatic detection. If driver
    doesn't detect device automatically, you need to check if pci id for your
    device is listed properly in the driver sources and add it if needed.

    If device is already detected but doesn't work for some reason you need to
    study driver sources for the reason of this.

    For more details you can check with kernel developers or driver author. I
    don't see any reason your chip is not going to be supported.

     
  • Josh Herrmann

    Josh Herrmann - 2012-08-16

    Thanks for your help. I have now successfully managed to get the audio working
    in uclinux. I have also integrated pocketsphinx into the kernel, and it now
    runs. But, it has a problem when trying to set the gain of the mic. The error
    is this:

    ad_oss.c 258: can't set input gain/recording level for this device.

    The thing is, I'm not using the old OSS audio system. I have built the ALSA
    libraries into the kernel. I also have figured out that in he sphinxbase
    makefile, if it can't find the ALSA header files, then it "falls back" on the
    OSS ones. I don't want it to do that. The other thing I noticed is that when
    running the configure script for sphinxbase, several printouts say:

    checking alsa/asoundlib.h usability... no
    checking alsa/asoundlib.h presence... no
    checking for alsa/asoundlib.h... no

    And further down:

    checking for SNDFILE... no
    checking sndfile.h usability... no
    checking sndfile.h presence... no
    checking for sndfile.h... no

    I'm fairly sure that the issue lies with the fact that, while cross-compiling
    sphinx for uclinux, it doesn't automatically detect the alsa files. So, all I
    need to know is what to specify in the configure script, so that those alsa
    files will be detected.

    Help would be highly appreciated.

     
  • Nickolay V. Shmyrev

    Thanks for your help. I have now successfully managed to get the audio
    working in uclinux. I have also integrated pocketsphinx into the kernel, and
    it now runs. But, it has a problem when trying to set the gain of the mic. The
    error is this:

    Congratulations

    I'm fairly sure that the issue lies with the fact that, while cross-
    compiling sphinx for uclinux, it doesn't automatically detect the alsa files.
    So, all I need to know is what to specify in the configure script, so that
    those alsa files will be detected.

    If alsa is properly installed on target development folder your compile should
    catch it automatically. Check compiler default search path where it looks for
    the library headers and binaries. If cross-compiler is built properly it
    should pick the files from the target filesystem or from other mirror of the
    target filesystem.

    Otherwise you need to set CFLAGS environment variable to let it found headers:

    CFLAGS="-I target_alsa_folder" LIBS="-L target_alsa_folder" ./configure --prefix....
    

    Then the configure will use those CFLAGS during tests and will find alsa and
    enable it.

     
  • Nickolay V. Shmyrev

    If alsa is properly installed on target development folder your compile
    should catch it automatically.

    In buildroot it's called "staging" directory.

     
  • Josh Herrmann

    Josh Herrmann - 2012-08-21

    Thanks for giving me those suggestions.

    Ok, the first thing I tried was cross compiling sphinxbase using just
    ./configure --host=bfin-uclinux. From what you said, the cross-compiler should
    have detected the ALSA headers and libraries automatically, but for me, it
    didn't.
    So, I then specified the CPPFLAGS parameter, and sphinxbase detected the alsa
    headers:

    checking alsa/asoundlib.h usability... yes
    checking alsa/asoundlib.h presence... yes
    checking for alsa/asoundlib.h... yes

    This looks good. But, the line below these says:

    checking for snd_pcm_open in -lasound... no

    "-lasound" as far as I know means to include a library called "asound", but
    since the check fails, it appears that the library wasn't located. So I then
    tried adding the LIBS and LDFLAGS parameter to specify the path to the ALSA
    libraries, so that bit looked like:

    LDFLAGS="-L/home/josh/uclinuxDev/uclinux-dist/staging/usr/lib"

    and CPPFLAGS was like this:

    CPPFLAGS="-I/home/josh/uclinuxDev/uclinux-dist/staging/usr/include"

    Even after adding the LDFLAGS parameter, I still had the check for the
    snd_pcm_open thing which failed.
    I then ran "make", and sphinxbase wouldn't compile. It had errors like these:

    /home/josh/uclinuxDev/sphinxFiles/sphinxbase/src/libsphinxad/ad_alsa.c:262:
    undefined reference to _snd_pcm_open' /home/josh/uclinuxDev/sphinxFiles/sphinxbase/src/libsphinxad/ad_alsa.c:264: undefined reference to_snd_strerror'

    And:

    ../../src/libsphinxad/.libs/libsphinxad.a(ad_alsa.o): In function ad_read': /home/josh/uclinuxDev/sphinxFiles/sphinxbase/src/libsphinxad/ad_alsa.c:378: undefined reference to_snd_pcm_readi'
    /home/josh/uclinuxDev/sphinxFiles/sphinxbase/src/libsphinxad/ad_alsa.c:407:
    undefined reference to `_snd_strerror'

    So do you know why the libraries aren't being included? All the header files
    and library files are within /path-to-kernel/staging/usr, but sphinxbase can
    only see the header files; the linker can't link the library files.
    f
    One other question: why didn't my cross compiler not detect them in the first
    place? You said it should automatically find them. The version of the kernel
    I'm using is 2010RC1-RC5 and the toolchain I'm using is 2010RC1-RC4

     
  • Josh Herrmann

    Josh Herrmann - 2012-08-22

    You know what, I managed to fix the problem. It turned out I was cross
    compiling sphinxbase and pocketsphinx the wrong way, so the ALSA audio
    libraries were never detected. Thanks for all your help with getting
    pocketsphinx to work on uclinux. I am now ready to move on to the next part of
    my project.

     
  • James Zhang

    James Zhang - 2012-08-31

    Hi,
    I have some problems like yours.I'm sure my alsa sub systerm working well on
    my board.But I can't compile it success.The problem is:
    checking alsa/asoundlib.h usability... no
    checking alsa/asoundlib.h presence... no
    checking for alsa/asoundlib.h... no
    and with the suggestion of
    LDFLAGS="-L/home/josh/uclinuxDev/uclinux-dist/staging/usr/lib"
    and CPPFLAGS was like this: CPPFLAGS="-I/home/josh/uclinuxDev/uclinux-
    dist/staging/usr/include"
    it didn't work else.
    so,could you give me some help or reference.
    thanks.

     
  • James Zhang

    James Zhang - 2012-09-01

    I have sovled my problem.It terned out that my direct is wrong.So
    carefullness!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.