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

TTS Time Service #455

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down
9 changes: 6 additions & 3 deletions js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ComicService,
GiphyService,
TrafficService,
TimeService,
TimerService,
ReminderService,
SearchService,
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions js/services/time.js
Original file line number Diff line number Diff line change
@@ -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');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never actually use vocal just say, which brings in unnecessary dependencies.

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);
}());