From 84689d1263524dea3430a388dbf84482b6fcc4b4 Mon Sep 17 00:00:00 2001 From: Gabriel Cohen Date: Sun, 27 Nov 2016 13:50:44 -0800 Subject: [PATCH 1/3] added tts time service --- bower.json | 3 ++- config.example.js | 1 + js/controller.js | 9 +++++--- js/services/time.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 js/services/time.js diff --git a/bower.json b/bower.json index 3978fb02c..21da820c2 100644 --- a/bower.json +++ b/bower.json @@ -23,7 +23,8 @@ "angular-i18n": "1.5.0", "angular-translate": "2.11.0", "angular-translate-loader-static-files": "2.11.0", - "rrule": "^2.1.0" + "rrule": "^2.1.0", + "vocal": "0.5.2" }, "overrides": { "moment": { diff --git a/config.example.js b/config.example.js index 2bf1a1131..87441d96c 100644 --- a/config.example.js +++ b/config.example.js @@ -14,6 +14,7 @@ var config = { }, layout: "main", greeting: ["Hi, sexy!", "Greetings, commander"], // An array of greetings to randomly choose from + time: "12", // can also be 24 // Alternativly you can have greetings that appear based on the time of day /* diff --git a/js/controller.js b/js/controller.js index cef0dc823..8a7832176 100644 --- a/js/controller.js +++ b/js/controller.js @@ -13,6 +13,7 @@ ComicService, GiphyService, TrafficService, + TimeService, TimerService, ReminderService, SearchService, @@ -454,9 +455,11 @@ $scope.focus = "reminders"; }); - // Check the time - addCommand('time_show', function (task) { - console.debug("It is", moment().format('h:mm:ss a')); + // Speak the time + addCommand('time_show', function() { + var timeFormat = config.time; // 12 or 24 + TimeService.speakTime(timeFormat); // do the speaking + $scope.focus = "default"; // show the clock }); // Control light diff --git a/js/services/time.js b/js/services/time.js new file mode 100644 index 000000000..b63e54ea0 --- /dev/null +++ b/js/services/time.js @@ -0,0 +1,50 @@ + (function() { + 'use strict'; + + // Gets time in 12-hour format + function getTime(timeFormat) { + var currentTime = new Date(); + var hours = currentTime.getHours(); + var minutes = currentTime.getMinutes(); + var time = "The time is "; + + // 24 hour + if (timeFormat == "24") { + time += hours + ":" + minutes; + } + + // 12 hour + else { + if (minutes < 10) { + minutes = "0" + minutes; + } + + else if (hours > 11) { + if (hours != 12) { + hours = hours - 12; + } + time += hours + ":" + minutes + " " + "PM"; + } + + else { // hours <= 11 + time += hours + ":" + minutes + " " + "AM"; + } + } + + return time; + } + + + function TimeService() { + var service = {}; + var say = require('say'); + service.speakTime = function(timeFormat) { + say.speak(getTime(timeFormat)); + // say.speak(getTime(), 'voice_kal_diphone', 0.5); // Can change parameters to use a different voice or change the speed + }; + return service; // donezo + } + + angular.module('SmartMirror') + .factory('TimeService', TimeService); + }()); From ea21adf21e0a924b0d95117e68d90c37c1763739 Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 3 Dec 2016 15:19:12 -0800 Subject: [PATCH 2/3] Changed import from vocal to say --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 21da820c2..e60327dae 100644 --- a/bower.json +++ b/bower.json @@ -24,7 +24,7 @@ "angular-translate": "2.11.0", "angular-translate-loader-static-files": "2.11.0", "rrule": "^2.1.0", - "vocal": "0.5.2" + "say": "0.11.0" }, "overrides": { "moment": { From 266a8f85b0ca0732d2411965d6ca0f87fddb2564 Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 3 Dec 2016 15:19:54 -0800 Subject: [PATCH 3/3] moved require to top of file --- js/services/time.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/services/time.js b/js/services/time.js index b63e54ea0..6db0d7821 100644 --- a/js/services/time.js +++ b/js/services/time.js @@ -1,5 +1,8 @@ (function() { 'use strict'; + + // use say for tts + var say = require('say'); // Gets time in 12-hour format function getTime(timeFormat) { @@ -37,7 +40,6 @@ function TimeService() { var service = {}; - var say = require('say'); service.speakTime = function(timeFormat) { say.speak(getTime(timeFormat)); // say.speak(getTime(), 'voice_kal_diphone', 0.5); // Can change parameters to use a different voice or change the speed