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

Review #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2

[{*.json, *.yml}]
indent_style = space
Expand Down
17 changes: 7 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
{
"env": {
"browser": true,
"node": true
},
"extends": "airbnb-base",
"root": true,
"rules": {
"comma-dangle": 0,
"indent": [2, 4],
"max-len": [2, 120, { "ignoreStrings": true }],
"radix": [2, "as-needed"],
"no-console": 0
"no-console": "off",
"radix": ["error", "as-needed"]
},
"settings": {
"import/core-modules": [ "node_helper" ]
},
"env": {
"browser": true,
"node": true,
"es6": true
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dependency directories
node_modules
82 changes: 44 additions & 38 deletions MMM-TTS.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global Module Log */

/* Magic Mirror
/*
* MagicMirror²
* Module: MMM-TTS
*
* By fewieden https://github.com/fewieden/MMM-TTS
Expand All @@ -9,42 +10,47 @@
*/

Module.register('MMM-TTS', {
tts: '',

defaults: {
text: 'MMM-TTS',
voice: null,
speed: 1.0,
debug: false
},

start() {
Log.info(`Starting module: ${this.name}`);
this.tts = this.config.text;
this.sendSocketNotification('CONFIG', this.config);
},

notificationReceived(notification, payload) {
if (notification === 'MMM-TTS') {
this.sendSocketNotification('TTS', payload);
this.tts = payload;
this.updateDom();
}
},

socketNotificationReceived(notification) {
if (notification === 'HIDE') {
this.tts = this.config.text;
this.updateDom();
}
},

getDom() {
const wrapper = document.createElement('div');
if (this.config.debug === true) {
wrapper.classList.add('thin', 'small', 'bright');
wrapper.innerHTML = this.tts;
}
return wrapper;
tts: '',

defaults: {
debug: false,
readAtStartup: true,
speed: 1.0,
text: 'Your mirror says hello!',
voice: null,
},

start() {
Log.info(`Starting module: ${this.name}`);
this.tts = this.config.text;
this.sendSocketNotification('CONFIG', this.config);
},

notificationReceived(notification, payload) {
if (this.config.readAtStartup && notification === 'ALL_MODULES_STARTED') {
this.sendSocketNotification('TTS', this.config.text);
}

if (notification === 'MMM-TTS') {
this.sendSocketNotification('TTS', payload);
this.tts = payload;
this.updateDom();
}
},

socketNotificationReceived(notification) {
if (notification === 'HIDE') {
this.tts = this.config.text;
this.updateDom();
}
},

getDom() {
const wrapper = document.createElement('div');
if (this.config.debug === true) {
wrapper.classList.add('thin', 'small', 'bright');
wrapper.innerHTML = this.tts;
}
return wrapper;
},
});
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
# MMM-TTS [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-TTS/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-TTS.svg?branch=master)](https://travis-ci.org/fewieden/MMM-TTS) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-TTS/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-TTS) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-tts/badge.svg)](https://snyk.io/test/github/fewieden/mmm-tts)

Text-To-Speech Module for MagicMirror<sup>2</sup>
Text-To-Speech module for [MagicMirror²](https://github.com/MichMich/MagicMirror).

## Dependencies

* An installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)
* An installation of MagicMirror².
* npm
* [say](https://www.npmjs.com/package/say)
* [festival](http://www.cstr.ed.ac.uk/projects/festival/)

## Installation

1. Clone this repo into `~/MagicMirror/modules` directory.
1. Configure your `~/MagicMirror/config/config.js`:
2. Configure your `~/MagicMirror/config/config.js`:

```
```js
{
module: 'MMM-TTS',
position: 'top_right',
config: {
...
readAtStartup: true,
speed: 1.0,
text: 'Hello, have a great day!'
}
}
```

1. Run command `npm install` in `~/MagicMirror/modules/MMM-TTS` directory.
1. Run command `sudo apt-get install festival`.
3. Run command `npm install` in `~/MagicMirror/modules/MMM-TTS` directory.
4. Run command `sudo apt-get install festival`.

## Config Options

| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `debug` | `false` | Display text to speech. |
| `text` | `'MMM-TTS'` | Text to display in debug mode, while there's no text to speech. |
| `voice` | `null` | If you want another voice than default you have to install it seperately and then fill in the voice name here. http://www.festvox.org/docs/manual-2.4.0/festival_24.html#Voices |
| `speed` | `1.0` | How fast the speech should be. |
| **Option** | **Default** | **Description** |
| --------------- | ----------- | --------------- |
| `debug` | `false` | Display text to speech. |
| `readAtStartup` | `true` | If set to true: Read the text when you start the mirror. |
| `speed` | `1.0` | How fast the speech should be. |
| `text` | `'Your mirror says hello!'` | Text to speak at startup and to display in debug mode, while there's no text to speech. |
| `voice` | `null` | If you want another voice than default you have to install it seperately and then fill in the voice name here. <http://www.festvox.org/docs/manual-2.4.0/festival_24.html#Voices> |

## For Developers

Expand Down
Binary file added docs/TTS.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions docs/TTS.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 15 additions & 16 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
/* Magic Mirror
/*
* MagicMirror²
* Module: MMM-TTS
*
* By fewieden https://github.com/fewieden/MMM-TTS
*
* MIT Licensed.
*/

/* eslint-env node */

const NodeHelper = require('node_helper');
const tts = require('say');

module.exports = NodeHelper.create({

start() {
console.log(`Starting node helper for: ${this.name}`);
},
start() {
console.log(`Starting node helper for: ${this.name}`);
},

socketNotificationReceived(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
} else if (notification === 'TTS') {
tts.speak(payload, this.config.voice, this.config.speed, (err) => {
if (err) {
console.log(err);
}
this.sendSocketNotification('HIDE', {});
});
socketNotificationReceived(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
} else if (notification === 'TTS') {
tts.speak(payload, this.config.voice, this.config.speed, (err) => {
if (err) {
console.log(err);
}
this.sendSocketNotification('HIDE', {});
});
}
},
});
Loading