Merge pull request #2035 from lissyx/electronjs

Build for ElectronJS
This commit is contained in:
lissyx 2019-04-11 09:43:55 +02:00 committed by GitHub
commit a05989439e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 248 additions and 3 deletions

View File

@ -36,13 +36,13 @@ configure: deepspeech_wrap.cxx package.json
$(NODE_BUILD_TOOL) configure $(NODE_BUILD_VERBOSE) $(NODE_BUILD_TOOL) configure $(NODE_BUILD_VERBOSE)
build: configure deepspeech_wrap.cxx build: configure deepspeech_wrap.cxx
AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(RPATH_NODEJS) $(LDFLAGS)" LIBS=$(LIBS) $(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_ABI_TARGET) rebuild $(NODE_BUILD_VERBOSE) AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(RPATH_NODEJS) $(LDFLAGS)" LIBS=$(LIBS) $(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_RUNTIME) $(NODE_ABI_TARGET) $(NODE_DIST_URL) rebuild $(NODE_BUILD_VERBOSE)
copy-deps: build copy-deps: build
$(call copy_missing_libs,lib/binding/*/*/*/deepspeech.node,lib/binding/*/*/) $(call copy_missing_libs,lib/binding/*/*/*/deepspeech.node,lib/binding/*/*/)
node-wrapper: copy-deps build node-wrapper: copy-deps build
$(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_ABI_TARGET) package $(NODE_BUILD_VERBOSE) $(NODE_BUILD_TOOL) $(NODE_PLATFORM_TARGET) $(NODE_RUNTIME) $(NODE_ABI_TARGET) $(NODE_DIST_URL) package $(NODE_BUILD_VERBOSE)
npm-pack: clean package.json README.md index.js npm-pack: clean package.json README.md index.js
npm install node-pre-gyp@0.12.x npm install node-pre-gyp@0.12.x

View File

@ -1,5 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict';
const Fs = require('fs'); const Fs = require('fs');
const Sox = require('sox-stream'); const Sox = require('sox-stream');
const Ds = require('./index.js'); const Ds = require('./index.js');
@ -40,6 +42,11 @@ util.inherits(VersionAction, argparse.Action);
VersionAction.prototype.call = function(parser) { VersionAction.prototype.call = function(parser) {
Ds.printVersions(); Ds.printVersions();
let runtime = 'Node';
if (process.versions.electron) {
runtime = 'Electron';
}
console.error('Runtime: ' + runtime);
process.exit(0); process.exit(0);
} }
@ -89,7 +96,7 @@ bufferToStream(buffer).
pipe(audioStream); pipe(audioStream);
audioStream.on('finish', () => { audioStream.on('finish', () => {
audioBuffer = audioStream.toBuffer(); let audioBuffer = audioStream.toBuffer();
console.error('Loading model from file %s', args['model']); console.error('Loading model from file %s', args['model']);
const model_load_start = process.hrtime(); const model_load_start = process.hrtime();
@ -115,4 +122,5 @@ audioStream.on('finish', () => {
console.log(model.stt(audioBuffer.slice(0, audioBuffer.length / 2), 16000)); console.log(model.stt(audioBuffer.slice(0, audioBuffer.length / 2), 16000));
const inference_stop = process.hrtime(inference_start); const inference_stop = process.hrtime(inference_start);
console.error('Inference took %ds for %ds audio file.', totalTime(inference_stop), audioLength.toPrecision(4)); console.error('Inference took %ds for %ds audio file.', totalTime(inference_stop), audioLength.toPrecision(4));
process.exit(0);
}); });

View File

@ -6,6 +6,9 @@ python:
brew: brew:
setup: 'install_local_homebrew "python-ds-test" && install_pkg_local_homebrew "sox" && install_pkg_local_homebrew "readline" && install_pkg_local_homebrew "openssl" && install_pkg_local_homebrew "pkg-config"' setup: 'install_local_homebrew "python-ds-test" && install_pkg_local_homebrew "sox" && install_pkg_local_homebrew "readline" && install_pkg_local_homebrew "openssl" && install_pkg_local_homebrew "pkg-config"'
env: 'export EXTRA_ENV="PATH=$TASKCLUSTER_TASK_DIR/python-ds-test.brew/bin/:$PATH"' env: 'export EXTRA_ENV="PATH=$TASKCLUSTER_TASK_DIR/python-ds-test.brew/bin/:$PATH"'
electronjs:
packages_xenial:
apt: 'libatk1.0-0 libatk-bridge2.0-0 libcairo2 libcups2 libdbus-1-3 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 xvfb'
nodejs: nodejs:
packages_trusty: packages_trusty:
apt: 'nodejs sox' apt: 'nodejs sox'

View File

@ -0,0 +1,13 @@
build:
template_file: test-darwin-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.brew.setup} && ${nodejs.brew.prep_10} && ${nodejs.brew.env}
args:
tests_cmdline: "$TASKCLUSTER_TASK_DIR/DeepSpeech/ds/tc-electron-tests.sh 10.x 3.1.8"
metadata:
name: "DeepSpeech OSX AMD64 CPU ElectronJS v3.1 tests"
description: "Testing DeepSpeech for OSX/AMD64 on ElectronJS v3.1, CPU only, optimized version"

View File

@ -0,0 +1,14 @@
build:
template_file: test-linux-opt-base.tyml
docker_image: "ubuntu:16.04"
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.packages_xenial.prep_10} && ${nodejs.packages_xenial.apt_pinning} && apt-get -qq update && apt-get -qq -y install ${nodejs.packages_xenial.apt} ${electronjs.packages_xenial.apt}
args:
tests_cmdline: "${system.homedir.linux}/DeepSpeech/ds/tc-electron-tests.sh 10.x 3.1.8"
metadata:
name: "DeepSpeech Linux AMD64 CPU ElectronJS v3.1 tests"
description: "Testing DeepSpeech for Linux/AMD64 on ElectronJS v3.1, CPU only, optimized version"

View File

@ -0,0 +1,13 @@
build:
template_file: test-win-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${system.sox_win} && ${nodejs.win.prep_10}
args:
tests_cmdline: "${system.homedir.win}/DeepSpeech/ds/tc-electron-tests.sh 10.x 3.1.8"
metadata:
name: "DeepSpeech Windows AMD64 CPU ElectronJS v3.1 tests"
description: "Testing DeepSpeech for Windows/AMD64 on ElectronJS v3.1, CPU only, optimized version"

View File

@ -0,0 +1,13 @@
build:
template_file: test-darwin-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.brew.setup} && ${nodejs.brew.prep_10} && ${nodejs.brew.env}
args:
tests_cmdline: "$TASKCLUSTER_TASK_DIR/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.0.3"
metadata:
name: "DeepSpeech OSX AMD64 CPU ElectronJS v4.0 tests"
description: "Testing DeepSpeech for OSX/AMD64 on ElectronJS v4.0, CPU only, optimized version"

View File

@ -0,0 +1,14 @@
build:
template_file: test-linux-opt-base.tyml
docker_image: "ubuntu:16.04"
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.packages_xenial.prep_10} && ${nodejs.packages_xenial.apt_pinning} && apt-get -qq update && apt-get -qq -y install ${nodejs.packages_xenial.apt} ${electronjs.packages_xenial.apt}
args:
tests_cmdline: "${system.homedir.linux}/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.0.3"
metadata:
name: "DeepSpeech Linux AMD64 CPU ElectronJS v4.0 tests"
description: "Testing DeepSpeech for Linux/AMD64 on ElectronJS v4.0, CPU only, optimized version"

View File

@ -0,0 +1,13 @@
build:
template_file: test-win-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${system.sox_win} && ${nodejs.win.prep_10}
args:
tests_cmdline: "${system.homedir.win}/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.0.3"
metadata:
name: "DeepSpeech Windows AMD64 CPU ElectronJS v4.0 tests"
description: "Testing DeepSpeech for Windows/AMD64 on ElectronJS v4.0, CPU only, optimized version"

View File

@ -0,0 +1,13 @@
build:
template_file: test-darwin-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.brew.setup} && ${nodejs.brew.prep_10} && ${nodejs.brew.env}
args:
tests_cmdline: "$TASKCLUSTER_TASK_DIR/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.1.1"
metadata:
name: "DeepSpeech OSX AMD64 CPU ElectronJS v4.1 tests"
description: "Testing DeepSpeech for OSX/AMD64 on ElectronJS v4.1, CPU only, optimized version"

View File

@ -0,0 +1,14 @@
build:
template_file: test-linux-opt-base.tyml
docker_image: "ubuntu:16.04"
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${nodejs.packages_xenial.prep_10} && ${nodejs.packages_xenial.apt_pinning} && apt-get -qq update && apt-get -qq -y install ${nodejs.packages_xenial.apt} ${electronjs.packages_xenial.apt}
args:
tests_cmdline: "${system.homedir.linux}/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.1.1"
metadata:
name: "DeepSpeech Linux AMD64 CPU ElectronJS v4.1 tests"
description: "Testing DeepSpeech for Linux/AMD64 on ElectronJS v4.1, CPU only, optimized version"

View File

@ -0,0 +1,13 @@
build:
template_file: test-win-opt-base.tyml
dependencies:
- "node-package-cpu"
- "test-training_upstream-linux-amd64-py27mu-opt"
system_setup:
>
${system.sox_win} && ${nodejs.win.prep_10}
args:
tests_cmdline: "${system.homedir.win}/DeepSpeech/ds/tc-electron-tests.sh 10.x 4.1.1"
metadata:
name: "DeepSpeech Windows AMD64 CPU ElectronJS v4.1 tests"
description: "Testing DeepSpeech for Windows/AMD64 on ElectronJS v4.1, CPU only, optimized version"

59
tc-electron-tests.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
set -xe
source $(dirname "$0")/tc-tests-utils.sh
nodever=$1
electronver=$2
if [ -z "${nodever}" ]; then
echo "No node version given, aborting."
exit 1
fi;
if [ -z "${electronver}" ]; then
echo "No electron version given, aborting."
exit 1
fi;
download_data
node --version
npm --version
NODE_ROOT="${DS_ROOT_TASK}/ds-test/"
export NODE_PATH="${NODE_ROOT}/node_modules/"
export PATH="${NODE_ROOT}:${NODE_PATH}/.bin/:${NODE_PATH}/electron/dist/:$PATH"
npm install --prefix ${NODE_ROOT} electron@${electronver}
npm install --prefix ${NODE_ROOT} ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz
if [ "${OS}" = "Darwin" ]; then
ln -s Electron.app/Contents/MacOS/Electron "${NODE_ROOT}/node_modules/electron/dist/node"
else
ln -s electron "${NODE_ROOT}/node_modules/electron/dist/node"
fi
find ${NODE_ROOT}/node_modules/electron/dist/
which electron
which node
if [ "${OS}" = "Linux" ]; then
export DISPLAY=':99.0'
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
xvfb_process=$!
fi
node --version
check_runtime_electronjs
run_electronjs_inference_tests
if [ "${OS}" = "Linux" ]; then
sleep 1
kill -9 ${xvfb_process} || true
fi

View File

@ -25,4 +25,6 @@ npm install ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz
export PATH=$HOME/node_modules/.bin/:$PATH export PATH=$HOME/node_modules/.bin/:$PATH
check_runtime_nodejs
run_prod_inference_tests run_prod_inference_tests

View File

@ -22,4 +22,6 @@ export PATH="${NODE_ROOT}:${NODE_PATH}/.bin/:$PATH"
npm install --prefix ${NODE_ROOT} ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz npm install --prefix ${NODE_ROOT} ${DEEPSPEECH_NODEJS}/deepspeech-${DS_VERSION}.tgz
check_runtime_nodejs
run_all_inference_tests run_all_inference_tests

View File

@ -57,6 +57,7 @@ model_source_mmap="$(dirname "${model_source}")/${model_name_mmap}"
SUPPORTED_PYTHON_VERSIONS=${SUPPORTED_PYTHON_VERSIONS:-2.7.15:ucs2 2.7.15:ucs4 3.4.9:ucs4 3.5.6:ucs4 3.6.7:ucs4 3.7.1:ucs4} SUPPORTED_PYTHON_VERSIONS=${SUPPORTED_PYTHON_VERSIONS:-2.7.15:ucs2 2.7.15:ucs4 3.4.9:ucs4 3.5.6:ucs4 3.6.7:ucs4 3.7.1:ucs4}
SUPPORTED_NODEJS_VERSIONS=${SUPPORTED_NODEJS_VERSIONS:-4.9.1 5.12.0 6.14.4 7.10.1 8.12.0 9.11.2 10.12.0 11.0.0} SUPPORTED_NODEJS_VERSIONS=${SUPPORTED_NODEJS_VERSIONS:-4.9.1 5.12.0 6.14.4 7.10.1 8.12.0 9.11.2 10.12.0 11.0.0}
SUPPORTED_ELECTRONJS_VERSIONS=${SUPPORTED_ELECTRONJS_VERSIONS:-1.6.18 1.7.16 1.8.8 2.0.18 3.0.16 3.1.8 4.0.3 4.1.4}
strip() { strip() {
echo "$(echo $1 | sed -e 's/^[[:space:]]+//' -e 's/[[:space:]]+$//')" echo "$(echo $1 | sed -e 's/^[[:space:]]+//' -e 's/[[:space:]]+$//')"
@ -284,6 +285,27 @@ check_tensorflow_version()
assert_deepspeech_version "${ds_help}" assert_deepspeech_version "${ds_help}"
} }
assert_deepspeech_runtime()
{
local expected_runtime=$1
set +e
local ds_version=$(${DS_BINARY_PREFIX}deepspeech --version 2>&1)
set -e
assert_shows_something "${ds_version}" "${expected_runtime}"
}
check_runtime_nodejs()
{
assert_deepspeech_runtime "Runtime: Node"
}
check_runtime_electronjs()
{
assert_deepspeech_runtime "Runtime: Electron"
}
run_tflite_basic_inference_tests() run_tflite_basic_inference_tests()
{ {
set +e set +e
@ -310,6 +332,24 @@ run_netframework_inference_tests()
assert_working_ldc93s1_lm "${phrase_pbmodel_withlm}" "$?" assert_working_ldc93s1_lm "${phrase_pbmodel_withlm}" "$?"
} }
run_electronjs_inference_tests()
{
set +e
phrase_pbmodel_nolm=$(deepspeech --model ${TASKCLUSTER_TMP_DIR}/${model_name} --alphabet ${TASKCLUSTER_TMP_DIR}/alphabet.txt --audio ${TASKCLUSTER_TMP_DIR}/LDC93S1.wav 2>${TASKCLUSTER_TMP_DIR}/stderr)
set -e
assert_working_ldc93s1 "${phrase_pbmodel_nolm}" "$?"
set +e
phrase_pbmodel_nolm=$(deepspeech --model ${TASKCLUSTER_TMP_DIR}/${model_name_mmap} --alphabet ${TASKCLUSTER_TMP_DIR}/alphabet.txt --audio ${TASKCLUSTER_TMP_DIR}/LDC93S1.wav 2>${TASKCLUSTER_TMP_DIR}/stderr)
set -e
assert_working_ldc93s1 "${phrase_pbmodel_nolm}" "$?"
set +e
phrase_pbmodel_withlm=$(deepspeech --model ${TASKCLUSTER_TMP_DIR}/${model_name_mmap} --alphabet ${TASKCLUSTER_TMP_DIR}/alphabet.txt --lm ${TASKCLUSTER_TMP_DIR}/lm.binary --trie ${TASKCLUSTER_TMP_DIR}/trie --audio ${TASKCLUSTER_TMP_DIR}/LDC93S1.wav 2>${TASKCLUSTER_TMP_DIR}/stderr)
set -e
assert_working_ldc93s1_lm "${phrase_pbmodel_withlm}" "$?"
}
run_basic_inference_tests() run_basic_inference_tests()
{ {
set +e set +e
@ -1110,6 +1150,17 @@ do_deepspeech_nodejs_build()
clean node-wrapper clean node-wrapper
done; done;
for electron in ${SUPPORTED_ELECTRONJS_VERSIONS}; do
EXTRA_CFLAGS="${EXTRA_LOCAL_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LOCAL_LDFLAGS}" EXTRA_LIBS="${EXTRA_LOCAL_LIBS}" make -C native_client/javascript \
TARGET=${SYSTEM_TARGET} \
RASPBIAN=${SYSTEM_RASPBIAN} \
TFDIR=${DS_TFDIR} \
NODE_ABI_TARGET=--target=$electron \
NODE_DIST_URL=--disturl=https://atom.io/download/electron \
NODE_RUNTIME=--runtime=electron \
clean node-wrapper
done;
if [ "${rename_to_gpu}" ]; then if [ "${rename_to_gpu}" ]; then
make -C native_client/javascript clean npm-pack PROJECT_NAME=deepspeech-gpu make -C native_client/javascript clean npm-pack PROJECT_NAME=deepspeech-gpu
else else