diff --git a/bower.json b/bower.json index 3978fb02c..e60327dae 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", + "say": "0.11.0" }, "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..6db0d7821 --- /dev/null +++ b/js/services/time.js @@ -0,0 +1,52 @@ + (function() { + 'use strict'; + + // use say for tts + var say = require('say'); + + // 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 = {}; + 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); + }());