### Install Binaries Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Installs the compiled library and binaries to the system path. ```bash PREFIX=/usr/local sudo make install ``` -------------------------------- ### Install Python Bindings Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Generates and installs the Python language bindings. ```bash cd native_client/python make bindings ``` -------------------------------- ### Install DeepSpeech and Download Models Source: https://github.com/mozilla/deepspeech/blob/master/doc/index.rst Installs DeepSpeech and downloads pre-trained English model files and example audio. Ensure you have Python 3 and virtualenv installed. ```bash # Create and activate a virtualenv virtualenv -p python3 $HOME/tmp/deepspeech-venv/ source $HOME/tmp/deepspeech-venv/bin/activate # Install DeepSpeech pip3 install deepspeech # Download pre-trained English model files curl -LO https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm curl -LO https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer # Download example audio files curl -LO https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/audio-0.9.3.tar.gz tar xvf audio-0.9.3.tar.gz # Transcribe an audio file deepspeech --model deepspeech-0.9.3-models.pbmm --scorer deepspeech-0.9.3-models.scorer --audio audio/2830-3980-0043.wav ``` -------------------------------- ### Install System Build Tools Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Installs system-level development headers required for building Python modules like webrtcvad. ```bash sudo apt-get install python3-dev ``` -------------------------------- ### Run DeepSpeech Inference Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Example command to perform speech-to-text on an audio file using the installed deepspeech binary. Assumes pre-trained models have been downloaded. ```bash ``` -------------------------------- ### Install Header Files Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/CMakeLists.txt Installs header files from the include/ directory to the destination include/ directory, matching files with the .h pattern. ```cmake install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Install Training Dependencies Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Installs required Python packages and the DeepSpeech training package in editable mode. ```bash cd DeepSpeech pip3 install --upgrade pip==20.2.2 wheel==0.34.2 setuptools==49.6.0 pip3 install --upgrade -e . ``` -------------------------------- ### Install MSYS2 Packages Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING_DotNet.rst Install necessary packages (patch, unzip) using pacman for MSYS2. ```bash pacman -Syu pacman -Su pacman -S patch unzip ``` -------------------------------- ### Example Playback with Reverberation and Volume Maximization Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst This bash command uses the `play.py` script to play all samples from `test.sdb` with reverberation and maximized volume. It demonstrates applying specific augmentations during playback for testing purposes. ```bash bin/play.py --augment reverb[p=0.1,delay=50.0,decay=2.0] --augment volume --random test.sdb ``` -------------------------------- ### Check Bazel Version Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING_DotNet.rst Verify the installed Bazel version. ```bash bazel version ``` -------------------------------- ### Install KenLM Python Module Source: https://github.com/mozilla/deepspeech/blob/master/native_client/kenlm/README.md Install the KenLM Python module using pip. This command downloads and installs the module from the master branch of the GitHub repository. ```bash pip install https://github.com/kpu/kenlm/archive/master.zip ``` -------------------------------- ### Train Custom DeepSpeech Models Source: https://context7.com/mozilla/deepspeech/llms.txt Commands for setting up the training environment, installing dependencies, and executing the training process. ```bash # Clone the repository git clone --branch v0.9.3 https://github.com/mozilla/DeepSpeech # Set up virtual environment python3 -m venv $HOME/tmp/deepspeech-train-venv/ source $HOME/tmp/deepspeech-train-venv/bin/activate # Install dependencies cd DeepSpeech pip3 install --upgrade pip==20.2.2 wheel==0.34.2 setuptools==49.6.0 pip3 install --upgrade -e . # Install GPU support (optional, but recommended) pip3 uninstall tensorflow pip3 install 'tensorflow-gpu==1.15.4' # Prepare your data in CSV format with columns: # wav_filename,wav_filesize,transcript # Basic training command python3 DeepSpeech.py \ --train_files train.csv \ --dev_files dev.csv \ --test_files test.csv \ --epochs 75 \ --learning_rate 0.0001 \ --export_dir ./export # Training with checkpointing python3 DeepSpeech.py \ --train_files train.csv \ --dev_files dev.csv \ --test_files test.csv \ --checkpoint_dir ./checkpoints \ --epochs 75 # Export model for TFLite (mobile/embedded) python3 DeepSpeech.py \ --checkpoint_dir ./checkpoints \ --export_dir ./export \ --export_tflite ``` -------------------------------- ### Example Training with All Augmentations Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst This bash script demonstrates how to enable and configure multiple audio augmentation techniques during the DeepSpeech training process. It includes parameters for overlay, reverb, resampling, codec, volume, pitch, tempo, warp, frequency mask, time mask, dropout, add, and multiply augmentations. ```bash python -u DeepSpeech.py \ --train_files "train.sdb" \ --feature_cache ./feature.cache \ --cache_for_epochs 10 \ --epochs 100 \ --augment overlay[p=0.5,source=noise.sdb,layers=1,snr=50:20~10] \ --augment reverb[p=0.1,delay=50.0~30.0,decay=10.0:2.0~1.0] \ --augment resample[p=0.1,rate=12000:8000~4000] \ --augment codec[p=0.1,bitrate=48000:16000] \ --augment volume[p=0.1,dbfs=-10:-40] \ --augment pitch[p=0.1,pitch=1~0.2] \ --augment tempo[p=0.1,factor=1~0.5] \ --augment warp[p=0.1,nt=4,nf=1,wt=0.5:1.0,wf=0.1:0.2] \ --augment frequency_mask[p=0.1,n=1:3,size=1:5] \ --augment time_mask[p=0.1,domain=signal,n=3:10~2,size=50:100~40] \ --augment dropout[p=0.1,rate=0.05] \ --augment add[p=0.1,domain=signal,stddev=0~0.5] \ --augment multiply[p=0.1,domain=features,stddev=0~0.5] \ [...] ``` -------------------------------- ### Install DeepSpeech Python Bindings (CPU) Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Install the DeepSpeech package for CPU inference using pip3 after activating the virtual environment. This command also handles dependency installation. ```bash $ pip3 install deepspeech ``` -------------------------------- ### Install DeepSpeech Python package Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Install the DeepSpeech package from the local distribution directory. ```bash pip install dist/deepspeech* ``` -------------------------------- ### Install DeepSpeech Node.js Package Source: https://context7.com/mozilla/deepspeech/llms.txt Install the DeepSpeech Node.js bindings using npm. Supports CPU and GPU versions. ```bash npm install deepspeech npm install deepspeech-gpu ``` -------------------------------- ### Configure fstconst Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/const/CMakeLists.txt Builds the fstconst library from multiple source files and sets installation paths. ```cmake add_library(fstconst const8-fst.cc const16-fst.cc const64-fst.cc) target_link_libraries(fstconst fst) set_target_properties(fstconst PROPERTIES SOVERSION "${SOVERSION}" FOLDER constant ) install(TARGETS fstconst LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) ``` -------------------------------- ### Setting up a Conda Environment for Training Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst This bash snippet illustrates the initial step of setting up a separate environment for training DeepSpeech using Conda. It emphasizes the importance of using a dedicated environment to prevent conflicts and ensure a stable training setup. ```bash conda create --name deepspeech python=3.7 conda activate deepspeech ``` -------------------------------- ### Run Python Linter Source: https://github.com/mozilla/deepspeech/blob/master/CONTRIBUTING.rst Install and execute the project's linter to check for style issues and mistakes in Python code. ```bash pip install pylint cardboardlint cardboardlinter --refspec master ``` -------------------------------- ### Configure Augmentation Flags Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Syntax for applying augmentation types and an example using the overlay augmentation. ```bash --augment augmentation_type1[param1=value1,param2=value2,...] --augment augmentation_type2[param1=value1,param2=value2,...] ... ``` ```bash python3 DeepSpeech.py --augment overlay[p=0.1,source=/path/to/audio.sdb,snr=20.0] ... ``` -------------------------------- ### Install DeepSpeech Python Package Source: https://context7.com/mozilla/deepspeech/llms.txt Install the DeepSpeech Python package for CPU or GPU inference. Requires Python 3 and pip. Also downloads pre-trained model files. ```bash virtualenv -p python3 $HOME/tmp/deepspeepspeech-venv/ source $HOME/tmp/deepspeech-venv/bin/activate pip3 install deepspeech pip3 install deepspeech-gpu wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer ``` -------------------------------- ### Install Node.js DeepSpeech GPU Package Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst For Linux users with a supported NVIDIA GPU, install the GPU-specific package using npm. Ensure CUDA dependencies are met. ```bash npm install deepspeech-gpu ``` -------------------------------- ### Build CTC decoder package Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Compile the CTC decoder bindings with specified parallelism and install the resulting wheel. ```bash cd native_client/ctcdecode make bindings NUM_PROCESSES=8 pip install dist/*.whl ``` -------------------------------- ### Install Node.js DeepSpeech Package Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Use npm to install the Node.js bindings for DeepSpeech. Supports Node.js versions 4-13 and Electron.JS versions 1.6-7.1. ```bash npm install deepspeech ``` -------------------------------- ### Install DeepSpeech Python Bindings (GPU) Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Install the GPU-accelerated version of DeepSpeech for Linux systems with a supported NVIDIA GPU. Ensure CUDA dependencies are met. ```bash $ pip3 install deepspeech-gpu ``` -------------------------------- ### Configure FST Linear Executables Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/linear/CMakeLists.txt Builds and installs command-line tools for linear FST operations if binary support is enabled. ```cmake if(HAVE_BIN) add_executable(fstlinear fstlinear.cc) target_link_libraries(fstlinear fstlinearscript fstscript fst ${CMAKE_DL_LIBS} ) add_executable(fstloglinearapply fstloglinearapply.cc) target_link_libraries(fstloglinearapply fstlinearscript fstscript fst ${CMAKE_DL_LIBS} ) install(TARGETS fstlinear fstloglinearapply RUNTIME DESTINATION bin ) set_target_properties(fstlinear fstloglinearapply PROPERTIES FOLDER linear/bin ) endif(HAVE_BIN) ``` -------------------------------- ### Add fstngram Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/ngram/CMakeLists.txt Defines and configures the 'fstngram' static library, linking it against the 'fst' library and setting its installation properties. ```cmake file(GLOB HEADER_FILES ../../include/fst/extensions/ngram/*.h) message(STATUS "${HEADER_FILES}") add_library(fstngram bitmap-index.cc ngram-fst.cc nthbit.cc ${HEADER_FILES} ) target_link_libraries(fstngram fst ) set_target_properties(fstngram PROPERTIES SOVERSION "${SOVERSION}" FOLDER ngram ) install(TARGETS fstngram LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) ``` -------------------------------- ### Configure Git Pre-commit Hook for Linting Source: https://github.com/mozilla/deepspeech/blob/master/CONTRIBUTING.rst Installs a pre-commit hook that stashes uncommitted changes, runs cardboardlinter on the staged changes, and restores the working tree. ```bash cat <<\EOF > .git/hooks/pre-commit #!/bin/bash if [ ! -x "$(command -v cardboardlinter)" ]; then exit 0 fi # First, stash index and work dir, keeping only the # to-be-committed changes in the working directory. echo "Stashing working tree changes..." 1>&2 old_stash=$(git rev-parse -q --verify refs/stash) git stash save -q --keep-index new_stash=$(git rev-parse -q --verify refs/stash) # If there were no changes (e.g., `--amend` or `--allow-empty`) # then nothing was stashed, and we should skip everything, # including the tests themselves. (Presumably the tests passed # on the previous commit, so there is no need to re-run them.) if [ "$old_stash" = "$new_stash" ]; then echo "No changes, skipping lint." 1>&2 exit 0 fi # Run tests cardboardlinter --refspec HEAD -n auto status=$? # Restore changes echo "Restoring working tree changes..." 1>&2 git reset --hard -q && git stash apply --index -q && git stash drop -q # Exit with status from test-run: nonzero prevents commit exit $status EOF chmod +x .git/hooks/pre-commit ``` -------------------------------- ### Simulate Codec Augmentation at Epoch Start and End Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst These bash commands simulate the codec augmentation on a WAV file using the `play.py` script. The first command applies the augmentation at the beginning of an epoch (clock=0.0), and the second applies it at the end (clock=1.0), showing how to control the timing of augmentations. ```bash bin/play.py --augment codec[p=0.1,bitrate=48000:16000] --clock 0.0 test.wav ``` ```bash bin/play.py --augment codec[p=0.1,bitrate=48000:16000] --clock 1.0 test.wav ``` -------------------------------- ### Get TensorFlow Version Source: https://github.com/mozilla/deepspeech/blob/master/ISSUE_TEMPLATE.md Use this command to retrieve the installed TensorFlow version. Ensure TensorFlow is installed in your Python environment. ```bash python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" ``` -------------------------------- ### Run Sample Training Script Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Execute the convenience script to train on the small LDC93S1 sample dataset. ```bash ./bin/run-ldc93s1.sh ``` -------------------------------- ### Create and Load DeepSpeech Model Instance (C) Source: https://github.com/mozilla/deepspeech/blob/master/doc/C-Examples.rst Demonstrates how to create a DeepSpeech model instance and load a pre-trained model file. Ensure the model file path is correct. ```c #include "deepspeech.h" #include #include int main(int argc, char **argv) { SpeechRecognitionContext *ctx = deepspeech_init("deepspeech-0.9.3-models.pb", "deepspeech-0.9.3-models.scorer"); if (!ctx) { fprintf(stderr, "Failed to initialize DeepSpeech context!\n"); return 1; } printf("DeepSpeech context initialized successfully.\n"); // ... rest of the inference code ... // Free the context when done // deepspeech_free(ctx); return 0; } ``` -------------------------------- ### Initialize and use ThreadPool in C++ Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/ThreadPool/README.md Demonstrates creating a thread pool with a specified number of threads and retrieving results using futures. ```c++ // create thread pool with 4 worker threads ThreadPool pool(4); // enqueue and store future auto result = pool.enqueue([](int answer) { return answer; }, 42); // get result from future std::cout << result.get() << std::endl; ``` -------------------------------- ### Create Virtual Environment Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Initializes a new Python virtual environment in the specified directory. ```bash $ python3 -m venv $HOME/tmp/deepspeech-train-venv/ ``` -------------------------------- ### Generate Dockerfile for Building from Source Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Use the make command to generate the Dockerfile.build for automatically building DeepSpeech components from source. ```bash make Dockerfile.build ``` -------------------------------- ### TensorFlow Error Log Example Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Example of a common error message encountered when cuDNN fails to initialize during training. ```text tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [[{{node tower_0/conv1d/Conv2D}}]] ``` -------------------------------- ### Model Initialization and Configuration Source: https://context7.com/mozilla/deepspeech/llms.txt Methods for loading the acoustic model and configuring inference parameters like beam width. ```APIDOC ## Model(model_path) ### Description Initializes a new DeepSpeech model instance from a .pbmm or .tflite file. ### Parameters #### Request Body - **model_path** (string) - Required - Path to the acoustic model file. ## setBeamWidth(beam_width) ### Description Sets the beam width for the decoder. Larger values improve accuracy but increase computation time. ### Parameters #### Request Body - **beam_width** (int) - Required - The beam width value. ``` -------------------------------- ### Build Native Client for CPU Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING_DotNet.rst Compile the native client library for CPU support, including AVX/AVX2 optimizations. Ensure your CPU supports these instructions. ```bash bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" -c opt --copt=/arch:AVX --copt=/arch:AVX2 //native_client:libdeepspeech.so ``` -------------------------------- ### Install DeepSpeech GPU Version and Transcribe Audio Source: https://github.com/mozilla/deepspeech/blob/master/doc/index.rst Installs the GPU-enabled DeepSpeech package and demonstrates how to transcribe an audio file using a supported NVIDIA GPU. Requires CUDA dependencies. ```bash # Create and activate a virtualenv virtualenv -p python3 $HOME/tmp/deepspeech-gpu-venv/ source $HOME/tmp/deepspeech-gpu-venv/bin/activate # Install DeepSpeech CUDA enabled package pip3 install deepspeech-gpu # Transcribe an audio file. deepspeech --model deepspeech-0.9.3-models.pbmm --scorer deepspeech-0.9.3-models.scorer --audio audio/2830-3980-0043.wav ``` -------------------------------- ### Cross-build for LePotato ARM64 Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Build the DeepSpeech library for LePotato ARM64 using Bazel. ```bash 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 ``` -------------------------------- ### Configure TensorFlow for GPU Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Switches the standard TensorFlow installation to the GPU-enabled version. ```bash pip3 uninstall tensorflow pip3 install 'tensorflow-gpu==1.15.4' ``` -------------------------------- ### Enable Testing and Add Test Subdirectory Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/CMakeLists.txt Enables the testing framework and includes the 'test' subdirectory for test-related build configurations. ```cmake enable_testing() add_subdirectory(test) ``` -------------------------------- ### Display DeepSpeech Help Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Access the full list of command line options for the training script. ```bash python3 DeepSpeech.py --helpfull ``` -------------------------------- ### Compile KenLM with CMake Source: https://github.com/mozilla/deepspeech/blob/master/native_client/kenlm/README.md Standard build procedure using CMake to prepare the library. ```bash mkdir -p build cd build cmake .. make -j 4 ``` -------------------------------- ### Generate Javadoc with SWIG Source: https://github.com/mozilla/deepspeech/blob/master/native_client/java/libdeepspeech/src/main/java/org/deepspeech/libdeepspeech_doc/README.rst Run this command from the native_client/java directory to generate Javadoc documentation. Requires SWIG 4.0 or higher. ```bash swig -c++ -java -doxygen -package org.deepspeech.libdeepspeech -outdir libdeepspeech/src/main/java/org/deepspeech/libdeepspeech_doc -o jni/deepspeech_wrap.cpp jni/deepspeech.i ``` -------------------------------- ### Upgrade DeepSpeech Python Bindings (CPU) Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Update an existing DeepSpeech installation to the latest version using pip3. ```bash $ pip3 install --upgrade deepspeech ``` -------------------------------- ### DeepSpeech Inference Error Output Source: https://github.com/mozilla/deepspeech/wiki/Finding-TensorFlow-op-kernel-targets-when-you-add-new-operations-to-the-graph Example of the error message generated when a required TensorFlow operation is missing from the binary. ```bash $ ./deepspeech --model ../ldc93s1_export/output_graph.pb --alphabet ../data/alphabet.txt --audio ../data/ldc93s1/LDC93S1.wav TensorFlow: v1.14.0-14-g1aad02a78e DeepSpeech: v0.6.0-alpha.4-7-gff8f405 Warning: reading entire model file into memory. Transform model file into an mmapped graph to reduce heap usage. 2019-07-17 09:57:35.976319: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA Invalid argument: No OpKernel was registered to support Op 'Split' used by {{node cudnn_lstm/rnn/cond/rnn/multi_rnn_cell/cell_0/cudnn_compatible_lstm_cell/split}}with these attrs: [T=DT_FLOAT, num_split=4] Registered devices: [CPU] Registered kernels: [[cudnn_lstm/rnn/cond/rnn/multi_rnn_cell/cell_0/cudnn_compatible_lstm_cell/split]] Could not create model. ``` -------------------------------- ### Build libdeepspeech.so for Android Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Commands to build the shared library for ARM and ARM64 architectures using Bazel. ```bash 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++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so ``` ```bash 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++14 --copt=-D_GLIBCXX_USE_C99 //native_client:libdeepspeech.so ``` -------------------------------- ### Configure TensorFlow Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Prepares the TensorFlow environment for the build process. ```bash cd tensorflow ./configure ``` -------------------------------- ### Upgrade DeepSpeech Python Bindings (GPU) Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Update an existing GPU-specific DeepSpeech installation to the latest version using pip3. ```bash $ pip3 install --upgrade deepspeech-gpu ``` -------------------------------- ### Download DeepSpeech model files Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Use wget to download the required .pbmm model and .scorer files into the current directory. ```bash wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.pbmm wget https://github.com/mozilla/DeepSpeech/releases/download/v0.9.3/deepspeech-0.9.3-models.scorer ``` -------------------------------- ### Create and Load DeepSpeech Model Instance (.NET) Source: https://github.com/mozilla/deepspeech/blob/master/doc/DotNet-Examples.rst Instantiates a DeepSpeech model and loads the specified model file. Ensure the model file path is correct. ```csharp var model = new Model("model.pb"); model.LoadStateDict("model.pb"); model.SetScorer("deepspeech_0.6.0-models.scorer"); ``` -------------------------------- ### Create Model Instance and Load Model in Java Source: https://github.com/mozilla/deepspeech/blob/master/doc/Java-Examples.rst Instantiate a DeepSpeech model and load the pre-trained model files. Ensure the model and scorer files are accessible. ```java DeepSpeechModel model = new DeepSpeechModel("model.pbmm"); model.init("alphabet.txt", "output_graph.pb", 1, 1); model.loadModel("model.pbmm", "model.scorer"); ``` -------------------------------- ### Add ngram_fst Module Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/ngram/CMakeLists.txt Defines and configures the 'ngram_fst' shared module, linking it against the 'fst' library and setting its installation properties for Windows. ```cmake add_library(ngram_fst MODULE bitmap-index.cc ngram-fst.cc nthbit.cc ) set_target_properties(ngram_fst PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true FOLDER ngram/modules ) target_link_libraries(ngram_fst fst ) install(TARGETS ngram_fst LIBRARY DESTINATION lib/fst ) ``` -------------------------------- ### Configure FST Linear Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/linear/CMakeLists.txt Defines the library build process for linear scripts, including header file globbing and installation paths. ```cmake file(GLOB HEADER_FILES ../../include/fst/extensions/linear/*.h) message(STATUS "${HEADER_FILES}") if(HAVE_SCRIPT) add_library(fstlinearscript linearscript.cc ${HEADER_FILES} ) target_link_libraries(fstlinearscript fstscript fst ) set_target_properties(fstlinearscript PROPERTIES SOVERSION "${SOVERSION}" FOLDER linear ) install(TARGETS fstlinearscript LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) endif(HAVE_SCRIPT) ``` -------------------------------- ### Build Native Client with CUDA Support Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING_DotNet.rst Compile the native client library with CUDA support. This requires CUDA to be enabled during the configure.py step. ```bash bazel build --workspace_status_command="bash native_client/bazel_workspace_status_cmd.sh" -c opt --config=cuda --copt=/arch:AVX --copt=/arch:AVX2 //native_client:libdeepspeech.so ``` -------------------------------- ### Define fstlookahead library in CMake Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/lookahead/CMakeLists.txt Configures the fstlookahead library with its source files, links the fst dependency, and sets target properties for installation. ```cmake add_library(fstlookahead arc_lookahead-fst.cc ilabel_lookahead-fst.cc olabel_lookahead-fst.cc ) target_link_libraries(fstlookahead fst) set_target_properties(fstlookahead PROPERTIES SOVERSION "${SOVERSION}" FOLDER lookahead ) install(TARGETS fstlookahead LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) ``` -------------------------------- ### Define FST Module Helper Function Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/special/CMakeLists.txt Provides a reusable function to add FST modules with standard linking, property configuration, and installation paths. ```cmake function (add_module _name) add_library(${ARGV}) if (TARGET ${_name}) target_link_libraries(${_name} fst) set_target_properties(${_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true FOLDER special/modules ) endif() install(TARGETS ${_name} LIBRARY DESTINATION lib/fst) endfunction() add_module(phi-fst MODULE phi-fst.cc) add_module(rho-fst MODULE rho-fst.cc) add_module(sigma-fst MODULE sigma-fst.cc) ``` -------------------------------- ### Define fstfar Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/far/CMakeLists.txt Defines the fstfar library by compiling C++ source files and linking against the fst library. Installs the library to the 'lib' directory. ```cmake file(GLOB HEADER_FILES ../../include/fst/extensions/far/*.h) message(STATUS "${HEADER_FILES}") add_library(fstfar sttable.cc stlist.cc ${HEADER_FILES} ) target_link_libraries(fstfar fst) set_target_properties(fstfar PROPERTIES SOVERSION "${SOVERSION}" FOLDER far ) install(TARGETS fstfar LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) ``` -------------------------------- ### Run DeepSpeech Command-Line Client Source: https://github.com/mozilla/deepspeech/blob/master/doc/USING.rst Execute the DeepSpeech C++ command-line client with specified model, scorer, and audio file. Assumes pre-trained models are downloaded. ```bash ./deepspeech --model deepspeech-0.9.3-models.pbmm --scorer deepspeech-0.9.3-models.scorer --audio audio_input.wav ``` -------------------------------- ### Build CTC decoder with custom configuration Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Build the CTC decoder using custom SWIG distribution and platform settings. ```bash SWIG_DIST_URL=[...] PYTHON_PLATFORM_NAME=[...] make bindings pip install dist/*.whl ``` -------------------------------- ### Speech-to-Text with Metadata (Python) Source: https://context7.com/mozilla/deepspeech/llms.txt Get detailed transcription results including per-token timing information and confidence scores. Supports multiple candidate transcripts. ```python from deepspeech import Model import numpy as np import wave import json ds = Model('deepspeech-0.9.3-models.pbmm') ds.enableExternalScorer('deepspeech-0.9.3-models.scorer') fin = wave.open('audio.wav', 'rb') audio = np.frombuffer(fin.readframes(fin.getnframes()), np.int16) fin.close() # Get metadata with multiple candidate transcripts num_candidates = 3 metadata = ds.sttWithMetadata(audio, num_candidates) ``` -------------------------------- ### Generate Initial Scorer Package Source: https://github.com/mozilla/deepspeech/blob/master/doc/Scorer.rst Use this command to create an initial scorer package. The alpha and beta values used here will be overridden by lm_optimizer.py. ```bash generate_scorer_package --alphabet_config_path alphabet.config --vocab_list_file vocab.txt --package_path lm.binary --default_alpha 0.0 --default_beta 0.0 ``` -------------------------------- ### Build Language Bindings Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Uses the Makefile to compile language-specific bindings. ```bash cd ../DeepSpeech/native_client make deepspeech ``` -------------------------------- ### Define fstfarscript Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/far/CMakeLists.txt Defines the fstfarscript library if HAVE_SCRIPT is enabled. It compiles specific C++ files and links against fstfar, fstscript, and fst. Installs the library to the 'lib' directory. ```cmake if(HAVE_SCRIPT) add_library(fstfarscript far-class.cc farscript.cc getters.cc script-impl.cc strings.cc ) target_link_libraries(fstfarscript fstfar fstscript fst) set_target_properties(fstfarscript PROPERTIES SOVERSION "${SOVERSION}" FOLDER far ) install(TARGETS fstfarscript LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) endif(HAVE_SCRIPT) ``` -------------------------------- ### Custom Executable Addition Function Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/pdt/CMakeLists.txt Defines a custom function `add_executable2` to simplify adding executables. This function adds an executable, links it to necessary libraries, sets its folder property, and installs it. ```cmake function (add_executable2 _name) add_executable(${ARGV}) if (TARGET ${_name}) target_link_libraries(${_name} fstpdtscript fstscript fst ${CMAKE_DL_LIBS}) set_target_properties(${_name} PROPERTIES FOLDER pdt/bin ) endif() install(TARGETS ${_name} RUNTIME DESTINATION bin) endfunction() ``` -------------------------------- ### Generate Dockerfile for Training Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Generates the Dockerfile for training, optionally specifying a custom repository or branch. ```bash make Dockerfile.train ``` ```bash make Dockerfile.train DEEPSPEECH_REPO=git://your/fork DEEPSPEECH_SHA=origin/your-branch ``` -------------------------------- ### Create and Load Model Instance - JavaScript Source: https://github.com/mozilla/deepspeech/blob/master/doc/NodeJS-Examples.rst Instantiates a DeepSpeech model and loads the model files. Ensure the model and grammar files are correctly path-ed. ```javascript const model = new DeepSpeech.Model(modelPath); model.init(); model.loadGrammar(grammarPath); ``` -------------------------------- ### Define Executable Helper Function Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/far/CMakeLists.txt A CMake function to simplify adding executables, linking them with necessary libraries, setting their folder property, and installing them to the 'bin' directory. This is used when HAVE_BIN is enabled. ```cmake if(HAVE_BIN) function (add_executable2 _name) add_executable(${ARGV}) if (TARGET ${_name}) target_link_libraries(${_name} fstfarscript fstscript fst ${CMAKE_DL_LIBS}) set_target_properties(${_name} PROPERTIES FOLDER far/bin) endif() install(TARGETS ${_name} RUNTIME DESTINATION bin) endfunction() add_executable2(farcompilestrings farcompilestrings.cc) add_executable2(farcreate farcreate.cc) add_executable2(farequal farequal.cc) add_executable2(farextract farextract.cc) add_executable2(farinfo farinfo.cc) add_executable2(farisomorphic farisomorphic.cc) add_executable2(farprintstrings farprintstrings.cc) endif(HAVE_BIN) ``` -------------------------------- ### Define Executable Target with Dependencies Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/bin/CMakeLists.txt This CMake function defines an executable target, links it with specified libraries (fstscript, fst, CMAKE_DL_LIBS), and sets its folder property. It also handles the installation of the executable. ```cmake function (add_executable2 _name) add_executable(${ARGV}) if (TARGET ${_name}) target_link_libraries(${_name} fstscript fst ${CMAKE_DL_LIBS}) set_target_properties(${_name} PROPERTIES FOLDER bin) endif() install(TARGETS ${_name} RUNTIME DESTINATION bin) endfunction() ``` -------------------------------- ### Define and Link Compression Library Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/compress/CMakeLists.txt Defines the `fstcompressscript` library using C++ source files and header files. It links against `fstscript`, `fst`, and ZLIB. The library is versioned and installed to the 'lib' directory. ```cmake file(GLOB HEADER_FILES ../../include/fst/extensions/compress/*.h) message(STATUS "${HEADER_FILES}") add_library(fstcompressscript compress-script.cc ${HEADER_FILES} ) target_link_libraries(fstcompressscript fstscript fst ${ZLIBS} ) set_target_properties(fstcompressscript PROPERTIES SOVERSION "10" ) install(TARGETS fstcompressscript LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION lib ) ``` -------------------------------- ### Create Pre-Augmented Test Set Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst This bash command uses the `data_set_tool.py` script to create a pre-augmented test set. It applies overlay and resampling augmentations to `test.sdb` and saves the result to `test-augmented.sdb`, useful for preparing data for training or evaluation. ```bash bin/data_set_tool.py \ --augment overlay[source=noise.sdb,layers=1,snr=20~10] \ --augment resample[rate=12000:8000~4000] \ test.sdb test-augmented.sdb ``` -------------------------------- ### Create and Configure Release Branch Source: https://github.com/mozilla/deepspeech/wiki/Release-checklist Commands to create a new release branch and update CI configuration files to reference the new branch. ```bash $ cd DeepSpeech $ git checkout master && git pull $ git checkout -b r0.8 $ git push origin r0.8 $ git checkout -b add-r0.8 $ for i in .taskcluster.yml taskcluster/github-events.cyml; do sed -i.bak -e 's/- master/- r0.8/' $i; done $ git add .taskcluster.yml taskcluster/github-events.cyml $ git commit -m "Switch CI to r0.8" $ git push origin add-r0.8 ``` -------------------------------- ### Create DeepSpeech Model Instance (Python) Source: https://context7.com/mozilla/deepspeech/llms.txt Load a DeepSpeech model from a .pbmm file to perform speech-to-text inference. Optionally set beam width and retrieve model properties. ```python from deepspeech import Model import numpy as np import wave # Load the acoustic model ds = Model('deepspeech-0.9.3-models.pbmm') # Optionally set beam width (larger values give better results but slower) ds.setBeamWidth(500) # Get the sample rate expected by the model (typically 16000 Hz) sample_rate = ds.sampleRate() print(f"Model expects {sample_rate}Hz audio") # Get current beam width beam_width = ds.beamWidth() print(f"Beam width: {beam_width}") ``` -------------------------------- ### Cross-build for RPi3 ARMv7 Source: https://github.com/mozilla/deepspeech/blob/master/doc/BUILDING.rst Build the DeepSpeech library for Raspberry Pi 3 using Bazel. ```bash 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 ``` -------------------------------- ### Distributed Training with Horovod Source: https://github.com/mozilla/deepspeech/blob/master/doc/TRAINING.rst Command to initiate distributed training across multiple machines and GPUs using Horovod. Ensure homogenous hardware and software configurations across all nodes for stability. ```bash horovodrun -np 16 -H server1:4,server2:4,server3:4,server4:4 python3 DeepSpeech.py --train_files [...] --horovod ``` -------------------------------- ### Define and Message Header Files Source: https://github.com/mozilla/deepspeech/blob/master/native_client/ctcdecode/third_party/openfst-1.6.9-win/src/extensions/pdt/CMakeLists.txt This snippet defines a list of header files and prints their paths using the message command. ```cmake file(GLOB HEADER_FILES ../../include/fst/extensions/pdt/*.h) message(STATUS "${HEADER_FILES}") ```