evancohen / sonus

:speech_balloon: /so.nus/ STT (speech to text) for Node with offline hotword detection
MIT License
618 stars 79 forks source link

npm run sonus - script not found #73

Closed ag-ni closed 6 years ago

ag-ni commented 6 years ago

Hi Evan,

I was able to complete installation, thanks a lot for your help. But now I am having issues when I am trying to start the program.

npm run sonus npm ERR! Linux 4.9.59-v7+ npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "sonus" npm ERR! node v5.12.0 npm ERR! npm v3.8.6

npm ERR! missing script: sonus npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request: npm ERR! /home/pi/sonus/npm-debug.log

I also tried starting the program using command

node sonus.js which gives me the below error --

module.js:341 throw err; ^

Error: Cannot find module '/home/pi/sonus_2/../index.js' at Function.Module._resolveFilename (module.js:339:15) at Function.Module._load (module.js:290:25) at Module.require (module.js:367:17) at require (internal/module.js:20:19) at Object. (/home/pi/sonus_2/server.js:4:15) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Function.Module.runMain (module.js:447:10)

I have sonus.js file in /home/pi/sonus directory though. Below is my sonus.js -

cat sonus.js 'use strict'

const ROOT_DIR = __dirname + '/../' const Sonus = require(ROOT_DIR + 'index.js') const speech = require('@google-cloud/speech')({ projectId: 'stt-homeauto', keyFilename: ROOT_DIR + 'stt-85f8543415bb58.json' })

const hotwords = [{ file: ROOT_DIR + 'resources/snowboy.pmdl', hotword: 'snowboy' }] const language = "en-US"

//recordProgram can also be 'arecord' which works much better on the Pi and low power devices const sonus = Sonus.init({ hotwords, language, recordProgram: "rec" }, speech)

Sonus.start(sonus) console.log('Say "' + hotwords[0].hotword + '"...')

sonus.on('hotword', (index, keyword) => console.log("!" + keyword))

sonus.on('partial-result', result => console.log("Partial", result))

sonus.on('error', error => console.log('error', error))

sonus.on('final-result', result => { console.log("Final", result) if (result.includes("stop")) { Sonus.stop() } })

evancohen commented 6 years ago

Change

const Sonus = require(ROOT_DIR + 'index.js')

To

const Sonus = require('sonus')
ag-ni commented 6 years ago

Hi Evan, Thanks for quick response. I made the changes as per your suggestion but now it is throwing a new error -- pi@raspberrypi:~/sonus $ node sonus.js /home/pi/node_modules/sonus/index.js:5 const { Detector, Models } = require('snowboy') ^

SyntaxError: Unexpected token { at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:20:19) at Object. (/home/pi/sonus/sonus.js:4:15) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10)

Regards

evancohen commented 6 years ago

This is valid Node syntax for node 5.x (though it's possible you're on a funky version?) you may want to try installing v6 or v7 and re-running the install so you get the correct binaries.

ag-ni commented 6 years ago

Hi Evan,

I am running node version 5.12.0. Plz see below -

pi@raspberrypi:~ $ node -v v5.12.0

I will install v6 or 7 and see if it works.

ag-ni commented 6 years ago

Hi Evan,

Thanks a lot for the suggestions. It worked.