Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@

*.log
node_modules

build/
build-pre-gyp/
Release/
deps/*/Debug/
*.so
*.a
*.sln
*.vcxproj
*.vcxproj.filters
*.tlog
*.obj
*.1sdk.pdb
*.lastbuildstate
prebuilds/
.nyc_output
23 changes: 23 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ endpoint is used for this transaction. This could be extended to allow the
user to update the title (and other meta data) at any time during the upload
process and have the data sent to the server in the background after each
update to the text fields.


### Sphinx

* https://cmusphinx.github.io/wiki/tutorialpocketsphinx/#installation-on-unix-system
* https://github.com/cmusphinx/sphinxbase
* https://github.com/cmusphinx/pocketsphinx
* https://github.com/cesine/cmuclmtk-for-nodejs


* https://docs.bazel.build/versions/master/install-os-x.html
* https://angular.io/guide/bazel
* https://ij.bazel.build/docs/import-project.html


## Development

```bash
npm install -g node-gyp
npm install
npm run rebuild
npm test
```
6 changes: 6 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"targets": [{
"target_name": "nodejs_sphinx",
"sources": ["src/nodejs-sphinx.cc"]
}]
}
5 changes: 5 additions & 0 deletions lib/nodejs-sphinx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var addon = require('bindings')('nodejs_sphinx');

module.exports = {
hello: addon.hello,
};
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
"lib": "lib"
},
"scripts": {
"install": "node-gyp-build",
"start": "node server.js",
"test": "mocha --recursive test",
"start": "node server.js"
"test-prebuild": "cross-env PREBUILDS_ONLY=1 npm t",
"rebuild": "npm run install --build-from-source",
"prebuild": "prebuildify -t 8.14.0 --napi --strip"
},
"gypfile": true,
"repository": {
"type": "git",
"url": "git+https://github.com/cesine/nodejs-sphinx.git"
Expand All @@ -23,13 +28,23 @@
"url": "https://github.com/cesine/nodejs-sphinx/issues"
},
"homepage": "https://github.com/cesine/nodejs-sphinx#readme",
"dependencies": {
"bindings": "^1.5.0",
"bunyan": "^1.8.12",
"formidable": "^1.2.1",
"napi-macros": "~2.0.0",
"node-gyp-build": "~4.1.0"
},
"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^6.0.0",
"mocha": "^6.2.2",
"node-gyp": "^6.0.0",
"prebuildify": "^3.0.0",
"prebuildify-ci": "^1.0.4",
"supertest": "^4.0.2"
},
"dependencies": {
"bunyan": "^1.8.12",
"formidable": "^1.2.1"
"engines": {
"node": ">=8.6.0"
}
}
18 changes: 13 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var formidable = require('./lib/formidable');
var paperboy = require('./lib/paperboy');

var log = bunyan.createLogger({
name: 'nodejs-sphinx'
name: 'nodejs-sphinx',
level: process.env.LOG_LEVEL || 'warn',
});

var PUBLIC = path.join(path.dirname(__filename), 'public');
Expand Down Expand Up @@ -47,7 +48,7 @@ function handleError(err, req, res) {
res.end();
}

function handleUpload(req, res) {
function handleUpload(req, res, next) {
var uuid = match[1];
uuid = uuid.replace(/.mp3/, "");
uuid = uuid.replace(/.srt/, "");
Expand Down Expand Up @@ -81,7 +82,14 @@ function handleUpload(req, res) {
//safeFilename=safeFilename.replace(/_client\./,".");
safeFilename = safeFilename.replace(/\.mp3/, ".amr");
var tempdir = "../nodejs-pocketsphinxtemp/";
fs.mkdirSync(tempdir);
try {
fs.mkdirSync(tempdir);
} catch (err) {
if (err.code !== 'EEXIST') {
return next(err);
}
log.info(err, 'Error creating directory');
}
fs.renameSync(path, tempdir + safeFilename);
safeFilenameServer = safeFilename.replace(/_client/, "_server");

Expand Down Expand Up @@ -223,13 +231,13 @@ function handleStatic(req, res) {
});
}

var server = http.createServer(function(req, res) {
var server = http.createServer(function(req, res, next) {
/*TODO check for API key and non banned install id in this regex */
regex = new RegExp('/upload/(.+)');
match = regex.exec(req.url);
if (match && req.method.toLowerCase() == 'post') {
try {
handleUpload(req, res);
handleUpload(req, res, next);
} catch (err) {
handleError(err, req, res);
}
Expand Down
25 changes: 25 additions & 0 deletions src/nodejs-sphinx.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define NAPI_VERSION 3

#include <assert.h>
#include <node_api.h>

napi_value Method(napi_env env, napi_callback_info info) {
napi_status status;
napi_value world;
status = napi_create_string_utf8(env, "world", 5, &world);
assert(status == napi_ok);
return world;
}

#define DECLARE_NAPI_METHOD(name, func) \
{ name, 0, func, 0, 0, 0, napi_default, 0 }

napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method);
status = napi_define_properties(env, exports, 1, &desc);
assert(status == napi_ok);
return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
9 changes: 9 additions & 0 deletions test/nodejs-sphinx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var expect = require('chai').expect;

var lib = require('../lib/nodejs-sphinx');

describe('/nodejs-sphinx', function() {
it('should load', function() {
expect(lib.hello()).to.equal('world');
});
});