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

Develop #38

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1bae2ec
update to support additional sleep modes, and communication with MMM-…
sdetweil Jun 10, 2018
ba1b9dd
update defaults and doc
sdetweil Jun 10, 2018
e1ff644
changes after review
sdetweil Jun 11, 2018
0c3aa1b
fix syntax errors
sdetweil Jun 11, 2018
7b54097
fix syntax errors
sdetweil Jun 11, 2018
62ecdee
fix syntax errors
sdetweil Jun 11, 2018
6d292f4
fix indentation errors
sdetweil Jun 14, 2018
584e7d1
fix indentation errors
sdetweil Jun 14, 2018
83a70fe
fix indentation
sdetweil Jun 14, 2018
ce83a1b
fix indentation
sdetweil Jun 14, 2018
c0df0c5
fix readme for option name change from Mode (already used) to standBy…
sdetweil Jun 14, 2018
c6f7923
fix case used for option comparison, use uppercase to match the readme
sdetweil Jun 14, 2018
1103b71
change notifications to pass payload
sdetweil Jun 14, 2018
afc9d94
fix syntax errors
sdetweil Jun 14, 2018
722a454
missing semicolon
sdetweil Jun 14, 2018
066d48d
fix self vs bind()
sdetweil Jun 15, 2018
166422c
fix syntax error
sdetweil Jun 15, 2018
c83f452
attempt to fix bind syntax.. proper operation with closing semicolon…
sdetweil Jun 15, 2018
a5dbf37
fix lint problem
sdetweil Jun 17, 2018
607d8af
try to fix lint problem
sdetweil Jun 17, 2018
f7e89c4
try to fix lint error
sdetweil Jun 17, 2018
9ce7e56
fix missing close paren on .bind()
sdetweil Jun 18, 2018
9d9f3fb
fix syntax error
sdetweil Jun 18, 2018
a71196e
bind syntax error, one more time
sdetweil Jun 18, 2018
fb87522
bind spacing again
sdetweil Jun 18, 2018
c4398e4
more generic notifications, updated readme, last recommendations of pr
fewieden Jun 22, 2018
59034d1
update type
fewieden Jun 22, 2018
9ba0d48
Merge pull request #23 from sdetweil/develop
fewieden Jun 22, 2018
7b55436
update config files
fewieden Dec 28, 2018
4c6a994
remove bytes
fewieden Dec 28, 2018
3cbd480
fs-extra, async/await, refactor node_helper
fewieden Dec 28, 2018
7a15c85
docs, nunjuck templates, stand by method improvements
fewieden Dec 28, 2018
76dd969
docs, nunjuck templates, stand by method improvements
fewieden Dec 28, 2018
3fb4ebf
Merge branch 'develop' of github.com:fewieden/MMM-voice into develop
fewieden Dec 28, 2018
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
17 changes: 8 additions & 9 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ engines:
enabled: true
config:
languages:
- javascript
- javascript
eslint:
enabled: true
channel: "eslint-3"
Expand All @@ -15,13 +15,12 @@ engines:
fixme:
enabled: true
markdownlint:
enabled: true
enabled: true
ratings:
paths:
- "**.js"
- "**.css"
- "**.md"
exclude_paths: [
"node_modules/**/*",
"Bytes.js"
]
- "**.css"
- "**.js"
- "**.md"
exclude_paths:
- "node_modules/**/*"
- "docs/**/*"
10 changes: 0 additions & 10 deletions .doclets.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Bytes.js
docs/*
23 changes: 16 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"indent": [2, 4],
"max-len": [2, 120, { "ignoreStrings": true }],
"radix": [2, "as-needed"],
"no-console": 0
"extends": ["esnext", "esnext/style-guide", "node", "node/style-guide"],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"settings": {
"import/core-modules": [ "node_helper" ]
Expand All @@ -14,5 +11,17 @@
"browser": true,
"node": true,
"es6": true
},
"rules": {
"import/no-commonjs": 0,
"import/no-nodejs-modules": 0,
"semi": 0,
"comma-dangle": 0,
"indent": ["error", 4],
"template-curly-spacing": 0,
"no-console": 0,
"curly": ["error", "all"],
"array-bracket-spacing": 0,
"space-before-function-paren": 0
}
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ npm-debug.log*
node_modules/

.idea/

docs/
2 changes: 1 addition & 1 deletion .mdlrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
all
rules "~MD013", "~MD026", "~MD033"
rules "~MD013", "~MD024", "~MD026", "~MD033"
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js
node_js:
- "stable"
- "7"
- "6"
- "5"
- "8"
- "9"
- "10"
script:
- npm run lint
cache:
Expand Down
274 changes: 0 additions & 274 deletions Bytes.js

This file was deleted.

20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# MMM-voice Changelog

## [2.0.0]

### Added

* Nunjuck templates
* Multiple stand by methods

### Changed

* Updated config files
* async/await on the node side of the module.
* fs-extra for promised based filesystem access.
* Documentation is now hosted on github pages instead of doclets.io (unmaintained).
* eslint recommended instead of airbnb ruleset.

### Removed

* Bytes.js (easteregg)
* Modals (help)

## [1.0.2]

### Fixed
Expand Down
135 changes: 53 additions & 82 deletions MMM-voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ Module.register('MMM-voice', {

/** @member {Object[]} modules - Set of all modules with mode and commands. */
modules: [],

/** @member {string[]} previouslyHidden - keep list of module identifiers already hidden when sleep occurs */
previouslyHidden: [],
/**
* @member {Object} defaults - Defines the default config values.
* @property {int} timeout - Seconds to active listen for commands.
* @property {string} keyword - Keyword to activate active listening.
* @property {boolean} debug - Flag to enable debug information.
* @property {string} standByMethod - Method which should be used to put the monitor in stand by.
*/
defaults: {
timeout: 15,
keyword: 'MAGIC MIRROR',
debug: false
debug: false,
standByMethod: 'TVSERVICE',
},

/**
Expand Down Expand Up @@ -112,55 +115,31 @@ Module.register('MMM-voice', {
},

/**
* @function getDom
* @description Creates the UI as DOM for displaying in MagicMirror application.
* @function getTemplate
* @description Nunjuck template.
* @override
*
* @returns {Element}
* @returns {string} Path to nunjuck template.
*/
getDom() {
const wrapper = document.createElement('div');
const voice = document.createElement('div');
voice.classList.add('small', 'align-left');

const icon = document.createElement('i');
icon.classList.add('fa', this.icon, 'icon');
if (this.pulsing) {
icon.classList.add('pulse');
}
voice.appendChild(icon);

const modeSpan = document.createElement('span');
modeSpan.innerHTML = this.mode;
voice.appendChild(modeSpan);
if (this.config.debug) {
const debug = document.createElement('div');
debug.innerHTML = this.debugInformation;
voice.appendChild(debug);
}

const modules = document.querySelectorAll('.module');
for (let i = 0; i < modules.length; i += 1) {
if (!modules[i].classList.contains(this.name)) {
if (this.help) {
modules[i].classList.add(`${this.name}-blur`);
} else {
modules[i].classList.remove(`${this.name}-blur`);
}
}
}

if (this.help) {
voice.classList.add(`${this.name}-blur`);
const modal = document.createElement('div');
modal.classList.add('modal');
this.appendHelp(modal);
wrapper.appendChild(modal);
}

wrapper.appendChild(voice);
getTemplate() {
return 'templates/MMM-voice.njk';
},

return wrapper;
/**
* @function getTemplateData
* @description Data that gets rendered in the nunjuck template.
* @override
*
* @returns {Object} Data for the nunjuck template.
*/
getTemplateData() {
return {
config: this.config,
icon: this.icon,
pulsing: this.pulsing,
mode: this.mode,
debugInformation: this.debugInformation
};
},

/**
Expand Down Expand Up @@ -214,52 +193,44 @@ Module.register('MMM-voice', {
break;
}
}
} else if (notification === 'BYTES') {
this.sendNotification('MMM-TTS', payload);
} else if (notification === 'HIDE') {
MM.getModules().enumerate((module) => {
module.hide(1000);
});
this.sendNotification('STAND_BY', { status: true, modules: [] });
} else if (notification === 'SHOW') {
MM.getModules().enumerate((module) => {
module.show(1000);
});
} else if (notification === 'OPEN_HELP') {
this.help = true;
} else if (notification === 'CLOSE_HELP') {
this.help = false;
this.sendNotification('STAND_BY', { status: false });
} else if (notification === 'STAND_BY_ACTION') {
if (payload.action === 'show') {
if (payload.hardware === false) {
MM.getModules().enumerate((module) => {
if (this.previouslyHidden.includes(module.identifier)) {
module.show(1000);
}
});
this.previouslyHidden = [];
}

this.sendNotification('STAND_BY', { status: false });
} else if (payload.action === 'hide') {
if (payload.hardware === false) {
MM.getModules().enumerate((module) => {
if (module.hidden === true) {
this.previouslyHidden.push(module.identifier);
} else {
module.hide(1000);
}
});
}

this.sendNotification('STAND_BY', { status: true, modules: this.previouslyHidden.slice(0) });
}
} else if (notification === 'DEBUG') {
this.debugInformation = payload;
}
this.updateDom(300);
},

/**
* @function appendHelp
* @description Creates the UI for the voice command SHOW HELP.
*
* @param {Element} appendTo - DOM Element where the UI gets appended as child.
*/
appendHelp(appendTo) {
const title = document.createElement('h1');
title.classList.add('medium');
title.innerHTML = `${this.name} - ${this.translate('COMMAND_LIST')}`;
appendTo.appendChild(title);

const mode = document.createElement('div');
mode.innerHTML = `${this.translate('MODE')}: ${this.voice.mode}`;
appendTo.appendChild(mode);

const listLabel = document.createElement('div');
listLabel.innerHTML = `${this.translate('VOICE_COMMANDS')}:`;
appendTo.appendChild(listLabel);

const list = document.createElement('ul');
for (let i = 0; i < this.voice.sentences.length; i += 1) {
const item = document.createElement('li');
item.innerHTML = this.voice.sentences[i];
list.appendChild(item);
}
appendTo.appendChild(list);
}
});
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# MMM-voice [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-voice/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-voice.svg?branch=master)](https://travis-ci.org/fewieden/MMM-voice) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-voice/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-voice) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-voice/badge.svg)](https://snyk.io/test/github/fewieden/mmm-voice) [![API Doc](https://doclets.io/fewieden/MMM-voice/master.svg)](https://doclets.io/fewieden/MMM-voice/master)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-voice/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-voice.svg?branch=master)](https://travis-ci.org/fewieden/MMM-voice) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-voice/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-voice) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-voice/badge.svg)](https://snyk.io/test/github/fewieden/mmm-voice) [![Documentation](https://img.shields.io/badge/Documentation-master-brightgreen.svg)](https://fewieden.github.io/MMM-voice/)

Voice Recognition Module for MagicMirror<sup>2</sup>
# MMM-voice

Offline Voice Recognition Module for MagicMirror<sup>2</sup>.

## Information

This voice recognition works offline. To protect your privacy, no one will record what's going on in your room all day long.
So keep in mind that there is no huge server farm, that handles your voice commands. The raspberry is just a small device and this is a cpu intensive task.
Also the dictionairy has only the words specified by the modules, so there is a chance for false positives.
Also the dictionary has only the words specified by the modules, so there is a chance for false positives.

If you can live with latency, bugged detections and want to have data privacy, feel free to use this module.

Expand All @@ -20,6 +22,8 @@ If you can live with latency, bugged detections and want to have data privacy, f
* npm
* [PocketSphinx-continuous](https://www.npmjs.com/package/pocketsphinx-continuous)
* [lmtool](https://www.npmjs.com/package/lmtool)
* [fs-extra](https://www.npmjs.com/package/fs-extra)
* [lodash](https://www.npmjs.com/package/lodash)

## Installation

Expand All @@ -33,7 +37,8 @@ If you can live with latency, bugged detections and want to have data privacy, f
position: 'bottom_bar',
config: {
microphone: 1,
...
standByMethod: 'TVSERVICE',
...
}
}
```
Expand All @@ -45,10 +50,11 @@ If you can live with latency, bugged detections and want to have data privacy, f
| `microphone` | REQUIRED | Id of microphone shown in the installer. |
| `keyword` | `'MAGIC MIRROR'` | Keyword the mirror starts to listen. IMPORTANT: Only UPPERCASE Letters |
| `timeout` | `15` | time the keyword should be active without saying something |
| `standByMethod` | `'TVSERVICE'` | `'TVSERVICE'` uses the tvservice command available on Raspberry pi to turn off the HDMI monitor source (default). <br>`'DPMS'` uses the exec DMPS command to turn off the monitor source (not on pi, or not hdmi). <br>`'VCGENCMD'` uses the vcgencmd to turn on/off video output. <br>`'HIDE'` hides all module contents, if display is on EnergyStar device that shows ugly 'no signal' screen for the other choices. |

## Usage

You need to say your KEYWORD (Default: MAGIC MIRROR), when the KEYWORD is recognized the microphone will start to flash and as long as the microphone is flashing (timeout config option) the mirror will recognize COMMANDS or MODES (Keep in mind that the recognition will take a while, so when you say your COMMAND right before the microphone stops flashing the COMMAND will propably not recognized).
You need to say your KEYWORD (Default: MAGIC MIRROR), when the KEYWORD is recognized the microphone will start to flash and as long as the microphone is flashing (timeout config option) the mirror will recognize COMMANDS or MODES (Keep in mind that the recognition will take a while, so when you say your COMMAND right before the microphone stops flashing the COMMAND will probably not recognized).

Mode of this module: `VOICE`

Expand All @@ -63,7 +69,7 @@ COMMANDS:

### Select Mode

To select a MODE, the specfic MODE has to be the first word of a COMMAND or right after the KEYWORD, when the microphone stopped flashing.
To select a MODE, the specific MODE has to be the first word of a COMMAND or right after the KEYWORD, when the microphone stopped flashing.

## Supported modules

Expand Down
Loading