DeepSpeech/native_client
2019-12-10 14:04:39 +01:00
..
ctcdecode Address review comment and add missing check for presence of scorer 2019-11-12 21:56:42 +01:00
dotnet Revert "Multi-stream support .NET" 2019-12-10 14:04:39 +01:00
java Remove outdated mention of DS_IntermediateDecode being expensive to call 2019-12-05 15:44:06 +01:00
javascript Use simple README pointing to GitHub for JS/Python packages 2019-12-06 17:33:00 +01:00
kenlm Add TFLite engine 2018-12-13 13:24:02 +01:00
python Use simple README pointing to GitHub for JS/Python packages 2019-12-06 17:33:00 +01:00
test Remove alphabet param usage 2019-11-05 09:02:42 +01:00
alphabet.h Document serialization format 2019-11-05 09:15:18 +01:00
Android.mk Building native_client on Android 2018-12-13 13:24:02 +01:00
args.h Remove alphabet param usage 2019-11-05 09:02:42 +01:00
bazel_workspace_status_cmd.sh Use bazel workspace status to generate versions 2019-06-25 18:03:52 -03:00
BUILD Add macOS debug symbol generation target for libdeepspeech 2019-10-11 18:13:12 +02:00
client.cc Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
CODINGSTYLE.md Update CODINGSTYLE.md 2019-06-22 21:41:48 +01:00
deepspeech_compat.h Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
deepspeech.cc Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
deepspeech.h Remove outdated mention of DS_IntermediateDecode being expensive to call 2019-12-05 15:44:06 +01:00
definitions.mk Move to ARMbian Buster 2019-08-21 22:58:10 +02:00
gen_workspace_status.sh Use bazel workspace status to generate versions 2019-06-25 18:03:52 -03:00
generate_trie.cpp Make Scorer init fallible and check it in callers 2019-08-26 13:59:15 +02:00
getopt_win.h Building on Windows 2019-03-12 22:21:01 +01:00
Makefile Move to ARMbian Buster 2019-08-21 22:58:10 +02:00
modelstate.cc Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
modelstate.h Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
multistrap_armbian64_buster.conf Move to ARMbian Buster 2019-08-21 22:58:10 +02:00
multistrap_raspbian_buster.conf Move Raspbian support to Buster 2019-08-20 16:37:26 +02:00
README.rst remove bad ticks 2019-12-03 13:42:35 -08:00
swig_node_v7x-v8x-v9x_0001.patch Patch SWIG locally with PR #968 2017-11-30 16:56:25 +01:00
swig_node_v7x-v8x-v9x_0002.patch Patch SWIG locally with PR #968 2017-11-30 16:56:25 +01:00
swig_node_v10.12.patch Add NodeJS v12 support 2019-04-25 15:43:16 +02:00
swig_node_v12_0001-Upgrade-SWIG-to-support-NodeJS-v12-V8-v7.6-v8-v7.8-r.patch Add ElectronJS v7.0 2019-11-05 12:26:52 +01:00
swig_py38_untrack.patch Build Python 3.8 wheels 2019-10-25 12:28:27 +02:00
tflitemodelstate.cc Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
tflitemodelstate.h Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
tfmodelstate.cc Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
tfmodelstate.h Embed alphabet directly in model 2019-11-05 09:02:21 +01:00
trie_load.cc Add debugging code to trie_load.cc 2019-10-15 12:43:03 +02:00
workspace_status.h Use bazel workspace status to generate versions 2019-06-25 18:03:52 -03:00
xldd Enable C++, NodeJS tests on RPi3 2018-04-16 11:35:54 +02:00

Building DeepSpeech Binaries
============================

If you'd like to build the DeepSpeech binaries yourself, you'll need the following pre-requisites downloaded and installed:


* `Mozilla's TensorFlow r1.14 branch <https://github.com/mozilla/tensorflow/tree/r1.14>`_
* `General TensorFlow requirements <https://www.tensorflow.org/install/install_sources>`_
* `libsox <https://sourceforge.net/projects/sox/>`_

It is required to use our fork of TensorFlow since it includes fixes for common problems encountered when building the native client files.

If you'd like to build the language bindings or the decoder package, you'll also need:


* `SWIG >= 3.0.12 <http://www.swig.org/>`_
* `node-pre-gyp <https://github.com/mapbox/node-pre-gyp>`_ (for Node.JS bindings only)

Dependencies
------------

If you follow these instructions, you should compile your own binaries of DeepSpeech (built on TensorFlow using Bazel).

For more information on configuring TensorFlow, read the docs up to the end of `"Configure the Build" <https://www.tensorflow.org/install/source#configure_the_build>`_.

TensorFlow: Clone & Checkout
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Clone our fork of TensorFlow and checkout the correct version:

.. code-block::

   git clone https://github.com/mozilla/tensorflow.git
   git checkout origin/r1.14

Bazel: Download & Install
^^^^^^^^^^^^^^^^^^^^^^^^^

First, `find the version of Bazel <https://www.tensorflow.org/install/source#tested_build_configurations>`_ you need for this TensorFlow release. Next, `download and install the correct version of Bazel <https://docs.bazel.build/versions/master/install.html>`_.

TensorFlow: Configure with Bazel
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After you have installed the correct version of Bazel, configure TensorFlow:

.. code-block::

   cd tensorflow
   ./configure

Compile DeepSpeech
------------------

Compile ``libdeepspeech.so`` & ``generate_trie``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Within your TensorFlow checkout, create a symbolic link to the DeepSpeech ``native_client`` directory. Assuming DeepSpeech and TensorFlow checkouts are in the same directory, do:

.. code-block::

   cd tensorflow
   ln -s ../DeepSpeech/native_client ./

You can now use Bazel to build the main DeepSpeech library, ``libdeepspeech.so``\ , as well as the ``generate_trie`` binary. Add ``--config=cuda`` if you want a CUDA build.

.. code-block::

   bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic -c opt --copt=-O3 --copt="-D_GLIBCXX_USE_CXX11_ABI=0" --copt=-fvisibility=hidden //native_client:libdeepspeech.so //native_client:generate_trie

The generated binaries will be saved to ``bazel-bin/native_client/``.

Compile Language Bindings
^^^^^^^^^^^^^^^^^^^^^^^^^

Now, ``cd`` into the ``DeepSpeech/native_client`` directory and use the ``Makefile`` to build all the language bindings (C++ client, Python package, Nodejs package, etc.). Set the environment variable ``TFDIR`` to point to your TensorFlow checkout.

.. code-block::

   TFDIR=~/tensorflow
   cd ../DeepSpeech/native_client
   make deepspeech

Installing your own Binaries
----------------------------

After building, the library files and binary can optionally be installed to a system path for ease of development. This is also a required step for bindings generation.

.. code-block::

   PREFIX=/usr/local sudo make install

It is assumed that ``$PREFIX/lib`` is a valid library path, otherwise you may need to alter your environment.

Install Python bindings
^^^^^^^^^^^^^^^^^^^^^^^

Included are a set of generated Python bindings. After following the above build and installation instructions, these can be installed by executing the following commands (or equivalent on your system):

.. code-block::

   cd native_client/python
   make bindings
   pip install dist/deepspeech*

The API mirrors the C++ API and is demonstrated in `client.py <python/client.py>`_. Refer to `deepspeech.h <deepspeech.h>`_ for documentation.

Install Node.JS bindings
^^^^^^^^^^^^^^^^^^^^^^^^

After following the above build and installation instructions, the Node.JS bindings can be built:

.. code-block::

   cd native_client/javascript
   make build
   make npm-pack

This will create the package ``deepspeech-VERSION.tgz`` in ``native_client/javascript``.

Install the CTC decoder package
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To build the ``ds_ctcdecoder`` package, you'll need the general requirements listed above (in particular SWIG). The command below builds the bindings using eight (8) processes for compilation. Adjust the parameter accordingly for more or less parallelism.

.. code-block::

   cd native_client/ctcdecode
   make bindings NUM_PROCESSES=8
   pip install dist/*.whl

Cross-building
--------------

RPi3 ARMv7 and LePotato ARM64
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We do support cross-compilation. Please refer to our ``mozilla/tensorflow`` fork, where we define the following ``--config`` flags:


* ``--config=rpi3`` and ``--config=rpi3_opt`` for Raspbian / ARMv7
* ``--config=rpi3-armv8`` and ``--config=rpi3-armv8_opt`` for ARMBian / ARM64

So your command line for ``RPi3`` and ``ARMv7`` should look like:

.. code-block::

   bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=rpi3 --config=rpi3_opt -c opt --copt=-O3 --copt=-fvisibility=hidden //native_client:libdeepspeech.so //native_client:generate_trie

And your command line for ``LePotato`` and ``ARM64`` should look like:

.. code-block::

   bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=rpi3-armv8 --config=rpi3-armv8_opt -c opt --copt=-O3 --copt=-fvisibility=hidden //native_client:libdeepspeech.so //native_client:generate_trie

While we test only on RPi3 Raspbian Buster and LePotato ARMBian Buster, anything compatible with ``armv7-a cortex-a53`` or ``armv8-a cortex-a53`` should be fine.

The ``deepspeech`` binary can also be cross-built, with ``TARGET=rpi3`` or ``TARGET=rpi3-armv8``. This might require you to setup a system tree using the tool ``multistrap`` and the multitrap configuration files: ``native_client/multistrap_armbian64_buster.conf`` and ``native_client/multistrap_raspbian_buster.conf``.
The path of the system tree can be overridden from the default values defined in ``definitions.mk`` through the ``RASPBIAN`` ``make`` variable.

.. code-block::

   cd ../DeepSpeech/native_client
   make TARGET=<system> deepspeech

Android devices
^^^^^^^^^^^^^^^

We have preliminary support for Android relying on TensorFlow Lite, with Java and JNI bindinds. For more details on how to experiment with those, please refer to ``native_client/java/README.rst``.

Please refer to TensorFlow documentation on how to setup the environment to build for Android (SDK and NDK required).

You can build the ``libdeepspeech.so`` using (ARMv7):

.. code-block::

   bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++11 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so

Or (ARM64):

.. code-block::

   bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" --config=monolithic --config=android --config=android_arm64 --define=runtime=tflite --action_env ANDROID_NDK_API_LEVEL=21 --cxxopt=-std=c++11 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so

Building the ``deepspeech`` binary will happen through ``ndk-build`` (ARMv7):

.. code-block::

   cd ../DeepSpeech/native_client
   $ANDROID_NDK_HOME/ndk-build APP_PLATFORM=android-21 APP_BUILD_SCRIPT=$(pwd)/Android.mk NDK_PROJECT_PATH=$(pwd) APP_STL=c++_shared TFDIR=$(pwd)/../../tensorflow/ TARGET_ARCH_ABI=armeabi-v7a

And (ARM64):

.. code-block::

   cd ../DeepSpeech/native_client
   $ANDROID_NDK_HOME/ndk-build APP_PLATFORM=android-21 APP_BUILD_SCRIPT=$(pwd)/Android.mk NDK_PROJECT_PATH=$(pwd) APP_STL=c++_shared TFDIR=$(pwd)/../../tensorflowx/ TARGET_ARCH_ABI=arm64-v8a