sdkcarlos / artyom.js

A voice control - voice commands - speech recognition and speech synthesis javascript library. Create your own siri,google now or cortana with Google Chrome within your website.
http://sdkcarlos.github.io/sites/artyom.html
MIT License
1.23k stars 370 forks source link

Artyom with express #42

Open 4bull opened 6 years ago

4bull commented 6 years ago

Hi, I'm trying to use artyom in a express nods app. I added with the following command (inside the project folders)

npm install artyom.js

And I see it in node_modules. In app.js I add the following lines:

var artyom = require('artyom.js/build/artyom.js');
const jarvis = new Artyom();

but when I start the app I got the following error:

const jarvis = new Artyom();
ReferenceError: Artyom is not defined

Any idea why? Thanks 4b

sdkcarlos commented 6 years ago

Have you tried just require("artyom.js") ? It should work out of the box requiring only the name of the module.

4bull commented 6 years ago

of course but no chance, doesn't work with only artyom.js, is for that I have tried with full path. Others module works out of the box.

Any others idea?

sdkcarlos commented 6 years ago

Ah, the error is not the module, check the uppercase:

var Artyom = require('artyom.js');

const jarvis = new Artyom();
4bull commented 6 years ago

yes, I found this typo error me too. Thanks but it doesn't work anyway.... I got

const jarvis = new Artyom();
               ^

TypeError: Artyom is not a constructor
mamihelj09 commented 6 years ago

Has anyone solved this?

webleyson commented 6 years ago

Are you running this in the browser?

alineo commented 6 years ago

Hello, I have the same issue :/ I want to use Artyom in a bot for Discord (made with node.js)

link imgur

const Artyom = require("artyom.js");
const artyom = new Artyom();

const artyom = new Artyom(); TypeError: Artyom is not a constructor

Does someone know what it is or what to do ? Thanks

DigitalFlux commented 6 years ago

I ran into this issue recently in working with this after doing npm install on nodejs, and found that changing: exports.default = Artyom; to: exports.Artyom = Artyom; At the end of build/artyom.js allowed me to do the following: var Artyom = require('./node_modules/artyom.js/build/artyom.js').Artyom; this.voice = new Artyom();

this being a class that assigns the new Artyom object to its voice member. I'm able to start it up, and now I'm just going through trying to get it to recognize any voice inputs (which may be a different issue than something inside Artyom, since I'm experimenting with node inside Electron right now).

If that issue has to do with Artyom, I'll update..

rodrigooler commented 5 years ago

same problem with electron :/

$ electron .
App threw an error during load
TypeError: Artyom is not a constructor
    at Object.<anonymous> (/Users/rodrigooler/proje
cts/friday/with-electron-app/main/index.js:7:16)
    at Object.<anonymous> (/Users/rodrigooler/proje
cts/friday/with-electron-app/main/index.js:49:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653
:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at loadApplicationPackage (/Users/rodrigooler/p
rojects/friday/with-electron-app/node_modules/elect
ron/dist/Electron.app/Contents/Resources/default_ap
p.asar/main.js:287:12)
    at Object.<anonymous> (/Users/rodrigooler/proje
cts/friday/with-electron-app/node_modules/electron/
dist/Electron.app/Contents/Resources/default_app.as
ar/main.js:328:5)
    at Object.<anonymous> (/Users/rodrigooler/proje
cts/friday/with-electron-app/node_modules/electron/
dist/Electron.app/Contents/Resources/default_app.as
ar/main.js:365:3)
DigitalFlux commented 5 years ago

Yeah, don't bother. Found that NWJS (and Electron, I believe) does not support voice recognition because Google pulled it from Chromium in order to get devs to use the cloud API. However, you can still do it through the browser, and what I wound up doing for my purposes was to pop a tab in Chrome with Artyom doing the voice recognition and an HTML "please don't close because XXX" blurb while routing the voice commands to NWJS via IPC. Works for now- would be nicer if Google put that bit back into Chromium instead of trying to force a cloud routing of voice data. But yeah, never got it to work on NodeJS as such.

rodrigooler commented 5 years ago

@DigitalFlux

I ran into this issue recently in working with this after doing npm install on nodejs, and found that changing:
exports.default = Artyom;
to:
exports.Artyom = Artyom;
At the end of build/artyom.js allowed me to do the following:
var Artyom = require('./node_modules/artyom.js/build/artyom.js').Artyom; this.voice = new Artyom();

this being a class that assigns the new Artyom object to its voice member. I'm able to start it up, and now I'm just going through trying to get it to recognize any voice inputs (which may be a different issue than something inside Artyom, since I'm experimenting with node inside Electron right now).

If that issue has to do with Artyom, I'll update..

In case I just managed to make it work because of your comment above to adjust the export unfortunately it is not working in the current version. I was able to make parts work on electron but I need to solve the window problem. I'll put the solution here if I can. I have not gotten into the problem you said yet, but it can be an unfortunate problem.

amreen-rajmohmad commented 3 years ago

Same here. I also tried the solution mentioned above about changing default export. following is the error i get : `(base) LT6564:node-server-tutorial amreen.rajmohmad$ node server.js /Users/amreen.rajmohmad/Documents/node-server-tutorial/node_modules/artyom.js/build/artyom.js:59 if (window.hasOwnProperty('speechSynthesis')) { ^

ReferenceError: window is not defined at new Artyom (/Users/amreen.rajmohmad/Documents/node-server-tutorial/node_modules/artyom.js/build/artyom.js:59:13) at Object. (/Users/amreen.rajmohmad/Documents/node-server-tutorial/server.js:11:16) at Module._compile (module.js:577:32) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.runMain (module.js:611:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:160:9)`

amreen-rajmohmad commented 3 years ago

Okay, So how i resolved this is :

const Artyom = require('artyom.js').default; since I was facing a windows error as I mentioned in my previous comment I saw there was already a PR addressing it.

https://github.com/sdkcarlos/artyom.js/pull/98/files

I replaced my Artyom.js file with these updated changes.

Then to make sure that node_modules use this changes : run following command from your package. it will create patches folder.

npx patch-package <package name> and add the following flag in your package.json so that on npm install this patch is applied again.

"postinstall": "npx patch-package"

https://stackoverflow.com/questions/13300137/how-to-edit-a-node-module-installed-via-npm