Skip to content

Commit

Permalink
Conversion to Makefile
Browse files Browse the repository at this point in the history
- Replaced setup.sh with target `standalone` in Makefile
- Updated documentation accordingly
- Updated CMakeLists_standalone to work with it now being used from Make (some path things for libdeepspeech.so)
- Fixed some wrongly formatted javadoc in DeepSpeechModel.java
  • Loading branch information
TheDutchMC committed Jan 19, 2021
1 parent 0fa0f15 commit c4874d2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 169 deletions.
6 changes: 3 additions & 3 deletions native_client/java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#User input
libdeepspeech/libs/*.so
#Native libs
libdeepspeech/libs/*
libdeepspeech/*.so

#Gradle
.gradle/
Expand All @@ -11,7 +12,6 @@ libdeepspeech/CMakeFiles/
libdeepspeech/cmake_install.cmake
libdeepspeech/CMakeCache.txt
libdeepspeech/Makefile
libdeepspeech/libdeepspeech-jni.so

#SWIG
jni/*.cpp
Expand Down
102 changes: 71 additions & 31 deletions native_client/java/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
.PHONY: clean apk-clean

include ../definitions.mk

ARCHS := $(shell grep 'ABI_FILTERS' libdeepspeech/gradle.properties | cut -d'=' -f2 | sed -e 's/;/ /g')
GRADLE ?= ./gradlew

all: apk

clean: apk-clean
rm -rf *.java jni/deepspeech_wrap.cpp

apk-clean:
$(GRADLE) clean

libs-clean:
rm -fr libdeepspeech/libs/*/libdeepspeech.so

libdeepspeech/libs/%/libdeepspeech.so:
-mkdir libdeepspeech/libs/$*/
cp ${TFDIR}/bazel-out/$*-*/bin/native_client/libdeepspeech.so libdeepspeech/libs/$*/

apk: apk-clean bindings $(patsubst %,libdeepspeech/libs/%/libdeepspeech.so,$(ARCHS))
$(GRADLE) build

maven-bundle: apk
$(GRADLE) uploadArchives
$(GRADLE) zipMavenArtifacts

bindings: clean ds-swig
$(DS_SWIG_ENV) swig -c++ -java -package org.deepspeech.libdeepspeech -outdir libdeepspeech/src/main/java/org/deepspeech/libdeepspeech/ -o jni/deepspeech_wrap.cpp jni/deepspeech.i
.PHONY: clean apk-clean jre jre-prepare jre-libdeepspeech-jni jre-gradle jre-collect jre-clean apk-prepare

include ../definitions.mk

ARCHS := $(shell grep 'ABI_FILTERS' libdeepspeech/gradle.properties | cut -d'=' -f2 | sed -e 's/;/ /g')
GRADLE ?= ./gradlew

all: apk jre
android: apk
standalone: jre

clean: apk-clean jre-clean
rm -rf *.java jni/deepspeech_wrap.cpp

apk-clean:
$(GRADLE) clean

libs-clean:
rm -fr libdeepspeech/libs/*/libdeepspeech.so

libdeepspeech/libs/%/libdeepspeech.so:
-mkdir libdeepspeech/libs/$*/
cp ${TFDIR}/bazel-out/$*-*/bin/native_client/libdeepspeech.so libdeepspeech/libs/$*/

apk-prepare:
cp build.gradle.android build.gradle
cp libdeepspeech/build.gradle.android libdeepspeech/build.gradle
cp libdeepspeech/CMakeLists_android.txt libdeepspeech/CMakeLists.txt

apk: apk-prepare apk-clean bindings $(patsubst %,libdeepspeech/libs/%/libdeepspeech.so,$(ARCHS))
$(GRADLE) build

jre: jre-prepare jre-collect jre-restore-makefile jre-clean
jre-prepare: $(patsubst %,libdeepspeech/libs/%/libdeepspeech.so,$(ARCHS))
cp Makefile Makefile.original
cp build.gradle.standalone build.gradle
cp libdeepspeech/build.gradle.standalone libdeepspeech/build.gradle
cp libdeepspeech/CMakeLists_standalone.txt libdeepspeech/CMakeLists.txt
sed -i 's|__JAVA_HOME__|'${JAVA_HOME}'|g' libdeepspeech/CMakeLists.txt

jre-libdeepspeech-jni: bindings
cd libdeepspeech; \
cmake .; \
$(MAKE)

jre-gradle: jre-libdeepspeech-jni
$(GRADLE) build

jre-collect: jre-gradle
mkdir -p build
mv libdeepspeech/libdeepspeech-jni.so build/
cp libdeepspeech/libs/x86_64/libdeepspeech.so build/
cp libdeepspeech/build/libs/libdeepspeech.jar build/

jre-clean:
rm -f libdeepspeech/CMakeLists.txt
rm -f libdeepspeech/build.gradle
rm -f build.gradle
rm -f jni/deepspeech_wrap.cpp jni/deepspeech_wrap.o
rm -rf libdeepspeech/cmake_install.cmake libdeepspeech/CMakeCache.txt libdeepspeech/Makefile libdeepspeech/CMakeFiles/
rm -rf libdeepspeech/build/

jre-restore-makefile:
mv Makefile.original Makefile

maven-bundle: apk
$(GRADLE) uploadArchives
$(GRADLE) zipMavenArtifacts

bindings: clean ds-swig
$(DS_SWIG_ENV) swig -c++ -java -package org.deepspeech.libdeepspeech -outdir libdeepspeech/src/main/java/org/deepspeech/libdeepspeech/ -o jni/deepspeech_wrap.cpp jni/deepspeech.i
11 changes: 4 additions & 7 deletions native_client/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ Full project description and documentation on GitHub: [https://github.com/mozill
## Android bindings
For use with Android

### Preparation
1. Rename `./build.gradle.android` to `build.gradle`
2. Rename `./libdeepspeech/build.gradle.android` to `build.gradle`
3. Rename `./libdeepspeech/CMakeLists_android.txt` to `CMakeLists.txt`

### Build
1. In `./` run `make`
``make android``

>Note: The current example app in `./App` is not up to date with the latest changes to the bindings!
## Standalone Java Bindings for DeepSpeech
For use with standalone Java

``make standalone``

### Usage information:
See [standalone.md](standalone.md)
4 changes: 2 additions & 2 deletions native_client/java/libdeepspeech/CMakeLists_standalone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ include_directories( ${CMAKE_JAVA_} __JAVA_HOME__/include __JAVA_HOME__/include/

add_library( deepspeech-jni SHARED ../jni/deepspeech_wrap.cpp )

find_library(deepspeech-lib NAMES deepspeech PATHS ${CMAKE_SOURCE_DIR}/libs/ REQUIRED)
find_library(deepspeech-lib NAMES deepspeech PATHS ${CMAKE_SOURCE_DIR}/libs/x86_64/ REQUIRED)
message(STATUS ${deepspeech-lib})

add_custom_command( TARGET deepspeech-jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/libs/libdeepspeech.so $ENV{CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libdeepspeech.so )
add_custom_command( TARGET deepspeech-jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/libs/x86_64/libdeepspeech.so ${CMAKE_SOURCE_DIR}/libdeepspeech.so )

target_link_libraries( deepspeech-jni ${deepspeech-lib} )
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void setScorerAlphaBeta(float alpha, float beta) {
evaluateErrorCode(impl.SetScorerAlphaBeta(this._msp, alpha, beta));
}

/*
/**
* @brief Use the DeepSpeech model to perform Speech-To-Text.
*
* @param buffer A 16-bit, mono raw audio signal at the appropriate
Expand Down
121 changes: 0 additions & 121 deletions native_client/java/setup.sh

This file was deleted.

5 changes: 1 addition & 4 deletions native_client/java/standalone.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
### Setup
1. Get `libdeepspeech.so` by compiling or (from here)[], and copy it into `./libdeepspeech/libs/`
2. Run `setup.sh` as root or with `sudo`
3. You can now find the files needed for your project at `./build/`
# DeepSpeech for standalone Java

### Adding DeepSpeech to your Java project
>Note: You can do this on your own way too, but this works with the example usage code provided below.
Expand Down

0 comments on commit c4874d2

Please sign in to comment.