@lumiastream/wakeword 1.0.1-alpha.7 → 1.0.1-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/wakeword CHANGED
@@ -24,7 +24,7 @@ const child = spawn(
24
24
  path.dirname(fileURLToPath(import.meta.url)),
25
25
  "..",
26
26
  "lib",
27
- "voice.mjs"
27
+ "voice.js"
28
28
  ),
29
29
  soxPath,
30
30
  ...process.argv.slice(2),
package/lib/record.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
 
3
- const assert = require("assert");
4
- const debug = require("debug")("record");
5
- const { spawn } = require("child_process");
6
- const recorders = require("./recorders");
3
+ import assert from "assert";
4
+ import debug from "debug";
5
+ import { spawn } from "child_process";
6
+ import recorders from "./recorders/index.js";
7
7
 
8
8
  class Recording {
9
9
  constructor(options = {}) {
@@ -114,6 +114,6 @@ Enable debugging with the environment variable DEBUG=record.`
114
114
  }
115
115
  }
116
116
 
117
- module.exports = {
117
+ export default {
118
118
  record: (...args) => new Recording(...args),
119
119
  };
@@ -1,5 +1,5 @@
1
1
  // On some systems (RasPi), arecord is the prefered recording binary
2
- module.exports = (options) => {
2
+ export default (options) => {
3
3
  let cmd = "arecord";
4
4
 
5
5
  if (options.binPath) {
@@ -1,18 +1,23 @@
1
- const path = require('path')
1
+ // import { fileURLToPath } from "node:url";
2
+ // import path from "node:path";
3
+ // const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
+ import rec from "./sox.js";
2
5
 
3
- function load (recorderName) {
4
- try {
5
- const recoderPath = path.resolve(__dirname, recorderName)
6
- return require(recoderPath)
7
- } catch (err) {
8
- if (err.code === 'MODULE_NOT_FOUND') {
9
- throw new Error(`No such recorder found: ${recorderName}`)
10
- }
6
+ function load(recorderName) {
7
+ try {
8
+ // const recoderPath = path.resolve(__dirname, recorderName);
9
+ // const module = await import(recoderPath);
10
+ // return module.default;
11
+ return rec;
12
+ } catch (err) {
13
+ if (err.code === "MODULE_NOT_FOUND") {
14
+ throw new Error(`No such recorder found: ${recorderName}`);
15
+ }
11
16
 
12
- throw err
13
- }
17
+ throw err;
18
+ }
14
19
  }
15
20
 
16
- module.exports = {
17
- load
18
- }
21
+ export default {
22
+ load,
23
+ };
@@ -1,4 +1,4 @@
1
- module.exports = (options) => {
1
+ export default (options) => {
2
2
  let cmd = "rec";
3
3
 
4
4
  if (options.binPath) {
@@ -1,4 +1,4 @@
1
- module.exports = (options) => {
1
+ export default (options) => {
2
2
  let cmd = "sox";
3
3
 
4
4
  if (options.binPath) {
@@ -1,6 +1,10 @@
1
- import { Model, Recognizer, setLogLevel } from "vosk";
2
- import record from "./record";
3
- import { join } from "node:path";
1
+ import { Model, Recognizer, setLogLevel } from "vosk-koffi";
2
+ import record from "./record.js";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { existsSync } from "node:fs";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
4
8
 
5
9
  const binPath = join(
6
10
  "binaries",
@@ -11,9 +15,8 @@ const binPath = join(
11
15
  : "soxlinux"
12
16
  );
13
17
 
14
- console.log(binPath);
15
-
16
18
  let COMMANDS = [
19
+ "blue",
17
20
  "[unk]", // always keep an [unk] fallback!
18
21
  ];
19
22
 
@@ -21,7 +24,18 @@ const SAMPLE_RATE = 16_000;
21
24
  setLogLevel(0);
22
25
 
23
26
  // 1. load model once
24
- const model = new Model("./models/vosk-model-small-en-us-0.15");
27
+ let modelPath = join(__dirname, "..", "models", "vosk-model-small-en-us-0.15");
28
+
29
+ /* If the file is running from inside app.asar we need the unpacked copy */
30
+ if (modelPath.includes("app.asar")) {
31
+ modelPath = modelPath.replace("app.asar", "app.asar.unpacked");
32
+ }
33
+
34
+ if (!existsSync(modelPath)) {
35
+ throw new Error(`Vosk model not found at ${modelPath}`);
36
+ }
37
+
38
+ const model = new Model(modelPath);
25
39
 
26
40
  // 2. build a grammar recognizer
27
41
  let rec = new Recognizer({
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@lumiastream/wakeword",
3
- "version": "1.0.1-alpha.7",
3
+ "version": "1.0.1-alpha.9",
4
4
  "type": "module",
5
- "main": "lib/voice.mjs",
5
+ "main": "lib/voice.js",
6
6
  "bin": {
7
7
  "wakeword": "bin/wakeword"
8
8
  },
@@ -16,6 +16,6 @@
16
16
  "postinstall": "chmod +x binaries/soxmac binaries/soxlinux binaries/sox.exe || true"
17
17
  },
18
18
  "dependencies": {
19
- "vosk": "^0.3.39"
19
+ "vosk-koffi": "^1.1.1"
20
20
  }
21
21
  }