diff --git a/Sphinx/LICENSE b/Sphinx/LICENSE new file mode 100644 index 0000000..b5d665e --- /dev/null +++ b/Sphinx/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 1999-2016 Carnegie Mellon University. All rights +reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +This work was supported in part by funding from the Defense Advanced +Research Projects Agency and the National Science Foundation of the +United States of America, and the CMU Sphinx Speech Consortium. + +THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND +ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY +NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Sphinx/builder/README.md b/Sphinx/builder/README.md new file mode 100644 index 0000000..1fcf3bc --- /dev/null +++ b/Sphinx/builder/README.md @@ -0,0 +1,91 @@ + +# CMU SphinxBase and PocketSphinx Builder + +> **DISCLAIMER**: TLSphinx comes with pre-bundled sphinxbase and pocketsphinx +> libraries and headers, you're **strongly** encouraged to use those instead of +> building them on your own. + +These are the CMU sphinxbase and pocketsphinx building instructions for TLSphinx, follow the guide below to build the required libraries for TLSphinx to build. + +In order to build sphinxbase and pocketsphinx both packages need to be downloaded, see: [CMUSphinx Downloads](https://cmusphinx.github.io/wiki/download/). + +From there you need to download: + + * [sphinxbase-5prealpha](http://sourceforge.net/projects/cmusphinx/files/sphinxbase/5prealpha) + * [pocketsphinx-5prealpha](http://sourceforge.net/projects/cmusphinx/files/pocketsphinx/5prealpha) + +After downloading both files copy them to `Sphinx/builder/cmusphinx` + +## Automatic Compilation +After copying the files to the appropiate directory (*see above*) just run the install.sh script and with some luck you're done. + +``` +cd Sphinx/builder/ +./install.sh +``` + + +--- +## Manual Compilation +If possible please try automatic compilation when possible, manual compilation is not for the feint of heart yet it might help in scenarios where you want to build CMU Sphinx Base and Pocket Sphinx from their respective master branches. + +Below are sample instructions on how to manually build the **5prealpha** release, to build against the lastest source just modify each command accordingly. +### Sphinxbase +--- +#### To prepare build environment: +``` +#From TLSphinx root directory +cd Sphinx/builder/cmusphinx +tar zxvf sphinxbase-5prealpha.tar.gz +cp ../ios-build-sphinxbase.sh sphinxbase-5prealpha/ +``` +#### To build: +``` +SPHINX_VERSION_REQ=5prealpha +cd sphinxbase-5prealpha +./ios-build-sphinxbase.sh +``` +#### Install Libraries: +``` +cp bin/arm64/lib/libsphinx*.a ../../../lib/sphinxbase/arm64/ +cp bin/armv7/lib/libsphinx*.a ../../../lib/sphinxbase/armv7/ +cp bin/armv7s/lib/libsphinx*.a ../../../lib/sphinxbase/armv7s/ +cp bin/i386/lib/libsphinx*.a ../../../lib/sphinxbase/i386/ +cp bin/x86_64/lib/libsphinx*.a ../../../lib/sphinxbase/x86_64/ +cp bin/libsphinxad.a ../../../lib/sphinxbase/ +cp bin/libsphinxbase.a ../../../lib/sphinxbase/ +``` +#### Install Headers +``` +cp include/sphinxbase/ ../../../include/sphinxbase/ +cp include/sphinx_config.h ../../../include/sphinxbase/ +``` + +### PocketSphinx +--- +#### To prepare build environment: +``` +#From TLSphinx root directory +cd Sphinx/builder/cmusphinx +tar zxvf pocketsphinx-5prealpha.tar.gz +cp ../ios-build-pocketsphinx.sh pocketsphinx-5prealpha/ +``` +#### To build: +``` +SPHINX_VERSION_REQ=5prealpha +cd pocketsphinx-5prealpha +./ios-build-pocketsphinx.sh +``` +#### Install Libraries: +``` +cp bin/arm64/lib/libpocketsphinx.a ../../../lib/pocketsphinx/arm64/ +cp bin/armv7/lib/libpocketsphinx.a ../../../lib/pocketsphinx/armv7/ +cp bin/armv7s/lib/libpocketsphinx.a ../../../lib/pocketsphinx/armv7s/ +cp bin/i386/lib/libpocketsphinx.a ../../../lib/pocketsphinx/i386/ +cp bin/x86_64/lib/libpocketsphinx.a ../../../lib/pocketsphinx/x86_64/ +cp bin/libpocketsphinx.a ../../../lib/pocketsphinx/ +``` +#### Install Headers +``` +cp -vf include/*.h ../../../include/pocketsphinx/ +``` \ No newline at end of file diff --git a/Sphinx/builder/cmusphinx/.gitignore b/Sphinx/builder/cmusphinx/.gitignore new file mode 100644 index 0000000..835f1ae --- /dev/null +++ b/Sphinx/builder/cmusphinx/.gitignore @@ -0,0 +1,2 @@ +*.tar.gz +*sphinx*/ diff --git a/Sphinx/builder/cmusphinx/README.md b/Sphinx/builder/cmusphinx/README.md new file mode 100644 index 0000000..d2ae0a9 --- /dev/null +++ b/Sphinx/builder/cmusphinx/README.md @@ -0,0 +1,4 @@ +Yes this is the directory where you should put + + * pocketsphinx-5prealpha.tar.gz + * sphinxbase-5prealpha.tar.Igz diff --git a/Sphinx/builder/install.sh b/Sphinx/builder/install.sh new file mode 100755 index 0000000..9d635b4 --- /dev/null +++ b/Sphinx/builder/install.sh @@ -0,0 +1,81 @@ +#!/bin/sh +SPHINX_VERSION_REQ=5prealpha +SPHINXBASE_RELEASE=sphinxbase-${SPHINX_VERSION_REQ} +POCKETSPHINX_RELEASE=pocketsphinx-${SPHINX_VERSION_REQ} +export SPHINX_VERSION_REQ + +SPHINXBASE_PKG=${SPHINXBASE_RELEASE}.tar.gz +POCKETSPHINX_PKG=${POCKETSPHINX}.tar.gz + +#Check Sphinx libraries are in place +if [ ! -f `pwd`/cmusphinx/${SPHINXBASE_RELEASE}.tar.gz ]; then + echo "Please follow the readme instrunctions on how to download ${SPHINXBASE_PKG}" + exit 1 +fi + +if [ ! -f `pwd`/cmusphinx/${POCKETSPHINX_RELEASE}.tar.gz ]; then + echo "Please follow the readme instrunctions on how to download ${POCKETSPHINX_PKG}" + exit 1 +fi + +cd cmusphinx +rm -f build.log > /dev/null 2>&1 + +for SPHINX_PROJECT in ${SPHINXBASE_RELEASE} ${POCKETSPHINX_RELEASE} +do + #Delete previous build directory if found + if [ -d ${SPHINX_PROJECT} ]; then + rm -rf ${SPHINX_PROJECT} + fi + tarfile=${SPHINX_PROJECT}.tar.gz + echo "Decompressing ${tarfile}..." + tar zxf $tarfile || exit 1 +done + +#Copy build scripts +cp -f ../ios-build-sphinxbase.sh ${SPHINXBASE_RELEASE}/ +cp -f ../ios-build-pocketsphinx.sh ${POCKETSPHINX_RELEASE}/ + +#Compile SphinxBase +cd $SPHINXBASE_RELEASE +./ios-build-sphinxbase.sh || exit 1 +cd .. +#Compile PocketSphinx +cd $POCKETSPHINX_RELEASE +./ios-build-pocketsphinx.sh || exit 1 +cd .. + +#rm -rf ../../../lib/*sphinx* +#rm -rf ../../../include/*sphinx* + +cd $SPHINXBASE_RELEASE +echo +echo "Installing SphinxBase libraries..." +cp -f bin/arm64/lib/libsphinx*.a ../../../lib/sphinxbase/arm64/ && +cp -f bin/armv7/lib/libsphinx*.a ../../../lib/sphinxbase/armv7/ && +cp -f bin/armv7s/lib/libsphinx*.a ../../../lib/sphinxbase/armv7s/ && +cp -f bin/i386/lib/libsphinx*.a ../../../lib/sphinxbase/i386/ && +cp -f bin/x86_64/lib/libsphinx*.a ../../../lib/sphinxbase/x86_64/ && +cp -f bin/libsphinxad.a ../../../lib/sphinxbase/ && +cp -f bin/libsphinxbase.a ../../../lib/sphinxbase/ || exit 1 +echo +echo "Installing SphinxBase header..." +cp -f include/sphinxbase/*.h ../../../include/sphinxbase/ && +cp -f include/sphinx_config.h ../../../include/sphinxbase/ || exit 1 +cd .. + +cd $POCKETSPHINX_RELEASE +echo +echo "Installing PocketSphinx libraries..." +cp -f bin/arm64/lib/libpocketsphinx.a ../../../lib/pocketsphinx/arm64/ && +cp -f bin/armv7/lib/libpocketsphinx.a ../../../lib/pocketsphinx/armv7/ && +cp -f bin/armv7s/lib/libpocketsphinx.a ../../../lib/pocketsphinx/armv7s/ && +cp -f bin/i386/lib/libpocketsphinx.a ../../../lib/pocketsphinx/i386/ && +cp -f bin/x86_64/lib/libpocketsphinx.a ../../../lib/pocketsphinx/x86_64/ && +cp -f bin/libpocketsphinx.a ../../../lib/pocketsphinx/ || exit 1 +echo +echo "Installing PocketSphinx headers..." +cp -vf include/*.h ../../../include/pocketsphinx/ || exit 1 + +cd .. +echo Done diff --git a/Sphinx/builder/ios-build-pocketsphinx.sh b/Sphinx/builder/ios-build-pocketsphinx.sh new file mode 100755 index 0000000..33bffb3 --- /dev/null +++ b/Sphinx/builder/ios-build-pocketsphinx.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +SCRATCH="scratch" +DEST=`pwd`/"bin" + +ARCHS="arm64 armv7 armv7s x86_64 i386" + +if [ "$*" ] +then + ARCHS="$*" +fi + +if [ "${SPHINX_VERSION_REQ}" != "" ]; then + SPHINX_VERSION_SUFFIX="-${SPHINX_VERSION_REQ}" +fi + +CWD=`pwd` + +for ARCH in $ARCHS +do + SPHINXBASE_DIR=`pwd`/../sphinxbase${SPHINX_VERSION_SUFFIX}/bin/$ARCH + echo "building $ARCH..." + mkdir -p "$SCRATCH/$ARCH" + cd "$SCRATCH/$ARCH" + + MIN_IOS_VERSION="8.0" + if [[ "${ARCH}" == "arm64" || "${ARCH}" == "x86_64" ]]; then + MIN_IOS_VERSION="7.0" # 7.0 as this is the minimum for these architectures + fi + + if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ] + then + PLATFORM="iPhoneSimulator" + IOS_CFLAGS="-arch $ARCH -mios-simulator-version-min=$MIN_IOS_VERSION" + else + PLATFORM="iPhoneOS" + IOS_CFLAGS="-arch $ARCH -mios-version-min=$MIN_IOS_VERSION -fembed-bitcode" + fi + + HOST_TYPE="${ARCH}-apple-darwin" + if [ "${ARCH}" == "arm64" ]; then + # Fix unknown type for arm64 cpu (which is aarch64) + HOST_TYPE="aarch64-apple-darwin" + fi + + export DEVELOPER=`xcode-select --print-path` + export DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" + export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${IPHONE_SDK}.sdk" + export CC=`xcrun -find clang` + export LD=`xcrun -find ld` + export CFLAGS="-O3 ${IOS_CFLAGS} -isysroot ${SDKROOT}" + export LDFLAGS="${IOS_CFLAGS} -isysroot ${SDKROOT}" + export CPPFLAGS="${CFLAGS}" + + $CWD/configure \ + --host="${HOST_TYPE}" \ + --prefix="$DEST/$ARCH" \ + --without-lapack \ + --without-python \ + --with-sphinxbase="$SPHINXBASE_DIR" \ + || exit 1 + + make -j3 install || exit 1 + cd $CWD +done + +PROJECT=pocketsphinx + +if [ ! "$*" ] +then + LIPO_ARGS="-output $DEST/lib$PROJECT.a" + for ARCH in $ARCHS + do + LIPO_ARGS="$LIPO_ARGS $DEST/$ARCH/lib/lib$PROJECT.a" + done + lipo -create $LIPO_ARGS || exit 1 +fi + +echo Done diff --git a/Sphinx/builder/ios-build-sphinxbase.sh b/Sphinx/builder/ios-build-sphinxbase.sh new file mode 100755 index 0000000..640c152 --- /dev/null +++ b/Sphinx/builder/ios-build-sphinxbase.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +SCRATCH="scratch" +DEST=`pwd`/"bin" + +ARCHS="arm64 armv7 armv7s x86_64 i386" + +if [ "$*" ] +then + ARCHS="$*" +fi + +if [ "${SPHINX_VERSION_REQ}" != "" ]; then + SPHINX_PKG_SUFFIX="-${SPHINX_VERSION_REQ}" +fi + +CWD=`pwd` + +for ARCH in $ARCHS +do + SPHINXBASE_DIR=`pwd`/../sphinxbase${SPHINX_VERSION_SUFFIX}/bin/$ARCH + echo "building $ARCH..." + mkdir -p "$SCRATCH/$ARCH" + cd "$SCRATCH/$ARCH" + + MIN_IOS_VERSION="8.0" + if [[ "${ARCH}" == "arm64" || "${ARCH}" == "x86_64" ]]; then + MIN_IOS_VERSION="7.0" # 7.0 as this is the minimum for these architectures + fi + + if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ] + then + PLATFORM="iPhoneSimulator" + IOS_CFLAGS="-arch $ARCH -mios-simulator-version-min=$MIN_IOS_VERSION" + else + PLATFORM="iPhoneOS" + IOS_CFLAGS="-arch $ARCH -mios-version-min=$MIN_IOS_VERSION -fembed-bitcode" + fi + + HOST_TYPE="${ARCH}-apple-darwin" + if [ "${ARCH}" == "arm64" ]; then + # Fix unknown type for arm64 cpu (which is aarch64) + HOST_TYPE="aarch64-apple-darwin" + fi + + export DEVELOPER=`xcode-select --print-path` + export DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" + export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${IPHONE_SDK}.sdk" + export CC=`xcrun -find clang` + export LD=`xcrun -find ld` + export CFLAGS="-O3 ${IOS_CFLAGS} -isysroot ${SDKROOT}" + export LDFLAGS="${IOS_CFLAGS} -isysroot ${SDKROOT}" + export CPPFLAGS="${CFLAGS}" + + $CWD/configure \ + --host="${HOST_TYPE}" \ + --prefix="$DEST/$ARCH" \ + --without-lapack \ + --without-python \ + --with-sphinxbase="$SPHINXBASE_DIR" \ + || exit 1 + + make -j3 install || exit 1 + cd $CWD +done + +PROJECT=sphinxbase + +if [ ! "$*" ] +then + LIPO_ARGS="-output $DEST/lib$PROJECT.a" + for ARCH in $ARCHS + do + LIPO_ARGS="$LIPO_ARGS $DEST/$ARCH/lib/lib$PROJECT.a" + done + lipo -create $LIPO_ARGS || exit 1 +fi +# libsphinxad +if [ ! "$*" ] +then + LIPO_ARGS="-output $DEST/libsphinxad.a" + for ARCH in $ARCHS + do + LIPO_ARGS="$LIPO_ARGS $DEST/$ARCH/lib/libsphinxad.a" + done + lipo -create $LIPO_ARGS || exit 1 +fi + +echo Done diff --git a/Sphinx/include/pocketsphinx/cmdln_macro.h b/Sphinx/include/pocketsphinx/cmdln_macro.h index 8a97b35..ff0ab81 100644 --- a/Sphinx/include/pocketsphinx/cmdln_macro.h +++ b/Sphinx/include/pocketsphinx/cmdln_macro.h @@ -154,7 +154,7 @@ { "-backtrace", \ ARG_BOOLEAN, \ "no", \ - "Print results and backtraces to log file." }, \ + "Print results and backtraces to log." }, \ { "-latsize", \ ARG_INT32, \ "5000", \ @@ -180,7 +180,7 @@ "25", \ "Window of frames in lattice to search for successor words in fwdflat search " } -/** Command-line options for keyword spotting */ +/** Command-line options for keyphrase spotting */ #define POCKETSPHINX_KWS_OPTIONS \ { "-keyphrase", \ ARG_STRING, \ @@ -193,7 +193,7 @@ { "-kws_plp", \ ARG_FLOAT64, \ "1e-1", \ - "Phone loop probability for keyword spotting" }, \ + "Phone loop probability for keyphrase spotting" }, \ { "-kws_delay", \ ARG_INT32, \ "10", \ @@ -243,7 +243,7 @@ { "-lmctl", \ ARG_STRING, \ NULL, \ - "Specify a set of language model\n"}, \ + "Specify a set of language model"}, \ { "-lmname", \ ARG_STRING, \ NULL, \ diff --git a/Sphinx/include/pocketsphinx/pocketsphinx.h b/Sphinx/include/pocketsphinx/pocketsphinx.h index ad8ac6f..c890b2b 100644 --- a/Sphinx/include/pocketsphinx/pocketsphinx.h +++ b/Sphinx/include/pocketsphinx/pocketsphinx.h @@ -408,17 +408,6 @@ int ps_end_utt(ps_decoder_t *ps); POCKETSPHINX_EXPORT char const *ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score); -/** - * Get hypothesis string and final flag. - * - * @param ps Decoder. - * @param out_is_best_score Output: if hypothesis is reached final state in the grammar. - * @return String containing best hypothesis at this point in - * decoding. NULL if no hypothesis is available. - */ -POCKETSPHINX_EXPORT -char const *ps_get_hyp_final(ps_decoder_t *ps, int32 *out_is_final); - /** * Get posterior probability. * diff --git a/Sphinx/include/pocketsphinx/ps_search.h b/Sphinx/include/pocketsphinx/ps_search.h index 8b5c696..8338752 100644 --- a/Sphinx/include/pocketsphinx/ps_search.h +++ b/Sphinx/include/pocketsphinx/ps_search.h @@ -39,7 +39,7 @@ * There are different possible search modes: * *