Hi,
I try to use jour Libary, but I'm realy new to node js.
So maybe this is a normal beginner question, but I don't found anything on "google" that matches my problem.
I use a Raspberry Pi 4 with a USB-Micro. I use the normal Raspberry Pi console os.
I have then update the OS and have done the folling steps:
sudo apt-get update ; sudo apt-get update -y ; sudo apt-get install sox;
sudo apt-get install nodejs npm
curl https://www.npmjs.com/install.sh | sudo sh
mkdir new_clap_npm; cd new_clap_npm;
npm install --save clap-detector
touch clap.js
This creates the folling in new_clap_npm:
drwxr-xr-x 3 pi pi 4096 Jul 21 12:46 . drwxr-xr-x 11 pi pi 4096 Jul 21 12:43 .. -rw-r--r-- 1 pi pi 1067 Jul 21 12:47 clap.js drwxr-xr-x 5 pi pi 4096 Jul 21 12:45 node_modules -rw-r--r-- 1 pi pi 58 Jul 21 12:45 package.json -rw-r--r-- 1 pi pi 1888 Jul 21 12:45 package-lock.json
I have then copy this into clap.js:
`import ClapDetector from 'clap-detector'
const clap = new ClapDetector()
const disposableOneClapListener = clap.addClapsListener(claps => {
console.log("heard 1 clap (force)", claps)
}, { number: 1, delay: 0, force: true })
const disposableOneClapForceListener = clap.addClapsListener(claps => {
console.log("heard 1 clap", claps)
}, { number: 1, delay: 1000 })
const disposableTwoClapsListener = clap.addClapsListener(claps => {
console.log("heard 2 claps", claps)
}, { number: 2, delay: 1000 })
const disposableThreeClapsListener = clap.addClapsListener(claps => {
console.log("heard 3 claps", claps)
}, { number: 3, delay: 1000 })
// Cancel some clap listeners
// Cancel alls claps listener but 2 claps after 10 seconds
setTimeout(() => {
console.log("only listen to 2 claps now")
disposableOneClapListener()
disposableOneClapForceListener()
disposableThreeClapsListener()
}, 10000)
// Dispose (stop sox process and listeners) after 30s
setTimeout(() => {
console.log("dispose all listeners and free ressources")
clap.dispose()
}, 30000)
`
If I try now to start with: I get
`/home/pi/new_clap_npm/clap.js:1
import ClapDetector from 'clap-detector'
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)`
Viso shows me this error on line 1:
Could not find a declaration file for module 'clap-detector'. '/home/pi/new_clap_npm/node_modules/clap-detector/lib/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/clap-detectorif it exists or add a new declaration (.d.ts) file containingdeclare module 'clap-detector';ts(7016) module "/home/pi/new_clap_npm/node_modules/clap-detector/lib/index"
If I try to do the Viso fix I get:
`pi@raspberrypi:~/new_clap_npm $ npm i --save-dev @types/clap-detector
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fclap-detector - Not found
npm ERR! 404
npm ERR! 404 '@types/clap-detector@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2021-07-21T11_06_57_973Z-debug.log`
Please help me to import your libary.
Best regards
Hi,
I try to use jour Libary, but I'm realy new to node js.
So maybe this is a normal beginner question, but I don't found anything on "google" that matches my problem.
I use a Raspberry Pi 4 with a USB-Micro. I use the normal Raspberry Pi console os.
I have then update the OS and have done the folling steps:
sudo apt-get update ; sudo apt-get update -y ; sudo apt-get install sox;sudo apt-get install nodejs npmcurl https://www.npmjs.com/install.sh | sudo shmkdir new_clap_npm; cd new_clap_npm;npm install --save clap-detectortouch clap.jsThis creates the folling in new_clap_npm:
drwxr-xr-x 3 pi pi 4096 Jul 21 12:46 . drwxr-xr-x 11 pi pi 4096 Jul 21 12:43 .. -rw-r--r-- 1 pi pi 1067 Jul 21 12:47 clap.js drwxr-xr-x 5 pi pi 4096 Jul 21 12:45 node_modules -rw-r--r-- 1 pi pi 58 Jul 21 12:45 package.json -rw-r--r-- 1 pi pi 1888 Jul 21 12:45 package-lock.jsonI have then copy this into clap.js:
`import ClapDetector from 'clap-detector'
const clap = new ClapDetector()
const disposableOneClapListener = clap.addClapsListener(claps => {
console.log("heard 1 clap (force)", claps)
}, { number: 1, delay: 0, force: true })
const disposableOneClapForceListener = clap.addClapsListener(claps => {
console.log("heard 1 clap", claps)
}, { number: 1, delay: 1000 })
const disposableTwoClapsListener = clap.addClapsListener(claps => {
console.log("heard 2 claps", claps)
}, { number: 2, delay: 1000 })
const disposableThreeClapsListener = clap.addClapsListener(claps => {
console.log("heard 3 claps", claps)
}, { number: 3, delay: 1000 })
// Cancel some clap listeners
// Cancel alls claps listener but 2 claps after 10 seconds
setTimeout(() => {
console.log("only listen to 2 claps now")
disposableOneClapListener()
disposableOneClapForceListener()
disposableThreeClapsListener()
}, 10000)
// Dispose (stop sox process and listeners) after 30s
setTimeout(() => {
console.log("dispose all listeners and free ressources")
clap.dispose()
}, 30000)
`
If I try now to start with: I get
`/home/pi/new_clap_npm/clap.js:1
import ClapDetector from 'clap-detector'
^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)`
Viso shows me this error on line 1:
Could not find a declaration file for module 'clap-detector'. '/home/pi/new_clap_npm/node_modules/clap-detector/lib/index.js' implicitly has an 'any' type. Trynpm i --save-dev @types/clap-detectorif it exists or add a new declaration (.d.ts) file containingdeclare module 'clap-detector';ts(7016) module "/home/pi/new_clap_npm/node_modules/clap-detector/lib/index"If I try to do the Viso fix I get:
`pi@raspberrypi:~/new_clap_npm $ npm i --save-dev @types/clap-detector
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fclap-detector - Not found
npm ERR! 404
npm ERR! 404 '@types/clap-detector@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2021-07-21T11_06_57_973Z-debug.log`
Please help me to import your libary.
Best regards