Recompiling PocketSphinx - dialogos-project/dialogos GitHub Wiki
The DialogOS PocketSphinx plugin relies on PocketSphinx, which is written in C and called from DialogOS via Swig. The DialogOS source code contains compiled dynamic libraries for PocketSphinx for Linux, MacOS, and Windows. If PocketSphinx needs to be ever recompiled, here's how.
Compile PocketSphinx and Sphinxbase from source as described on their pages. Then go to swig/java
in the PocketSphinx source distribution and run make
. This should create pocketsphinx.jar
, along with either libpocketsphinx_jni.so
(on Linux) or libpocketsphinx_jni.dylib
(on MacOS). These need to be copied over the respective files in the DialogOS source code.
The pocketsphinx.jar
is platform-independent and only needs to be generated once.
(If the maintainers of PocketSphinx do not accept our pull request for the Makefile, find it here.)
On MacOS, proceed as on Linux. Then you will need to fix the location in which the dynamic libraries look for the other dynamic libraries they depend on, so they don't insist on looking in /usr/local/lib
(which the Pocketsphinx Makefiles hard-code into the library files). Copy libsphinxbase.3.dylib
, libsphinxad.3.dylib
, libpocketsphinx.3.dylib
, and libpocketsphinx_jni.dylib
into your current directory and do the following:
install_name_tool -id libsphinxbase.3.dylib libsphinxbase.3.dylib
install_name_tool -id libsphinxad.3.dylib libsphinxad.3.dylib
install_name_tool -change /usr/local/lib/libsphinxbase.3.dylib "@loader_path/libsphinxbase.3.dylib" libsphinxad.3.dylib
install_name_tool -id libpocketsphinx.3.dylib libpocketsphinx.3.dylib
install_name_tool -change /usr/local/lib/libsphinxbase.3.dylib "@loader_path/libsphinxbase.3.dylib" libpocketsphinx.3.dylib
install_name_tool -change /usr/local/lib/libsphinxbase.3.dylib "@loader_path/libsphinxbase.3.dylib" libpocketsphinx_jni.dylib
install_name_tool -change /usr/local/lib/libpocketsphinx.3.dylib "@loader_path/libpocketsphinx.3.dylib" libpocketsphinx_jni.dylib
install_name_tool -change /usr/local/lib/libsphinxad.3.dylib "@loader_path/libsphinxad.3.dylib" libpocketsphinx_jni.dylib
You can use otool -L <libraryname.dylib>
to check whether the dependencies are right.
Things are a little more complicated under Windows, because one can't just use the Makefile that comes with PocketSphinx. Here are the necessary steps. These instructions assume that JAVA_HOME points to the correct directory, and that PocketSphinx and Sphinxbase are both in the same parent directory.
- Install a recent version of MS Visual Studio; the Community Edition is free. Use it to build PocketSphinx and SphinxBase as described in their documentation (both for 64-bit and 32-bit architectures).
- Install Cygwin, with swig, and run swig to generate
pocketsphinx_wrap.c
andsphinxbase_wrap.c
, as the Makefile in swig/java does. (Perhaps this can be done directly from a Windows shell, if you can get swig installed.) - Open an ordinary Windows shell and set the necessary paths for the MSVC compiler:
set PATH=d:\Progra~1\Micros~1\2017\Community\VC\Auxiliary\Build;%PATH%
(as of MSVC 2017; earlier versions had a different path to vcvarsall). Notice that you must have a path name without spaces; create a link toProgram Files (x86)
fromProgra~1
if necessary. - For each target architecture (64-bit and 32-bit DLLs), do the following steps:
-
vsvarsall x64
(64-bit) orvsvarsall amd64_x86
(generate 32-bit DLLs on a 64-bit host) - Copy the
sphinxbase.lib
andpocketsphinx.lib
that was generated for the target architecture from their respective build directories into swig/java. - Run the compiler to generate the DLL, once for each architecture:
cl pocketsphinx_wrap.c sphinxbase_wrap.c -I..\..\include -I..\..\..\sphinxbase\include -I..\..\..\sphinxbase\include\win32 -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 /link sphinxbase.lib pocketsphinx.lib /dll /out:pocketsphinx_jni.dll
- Copy the resulting DLL (together with the underlying PocketSphinx and SphinxBase DLLs) into the DialogOS source tree.
-