View Full Version : Talking Clock - Version 1

01-21-2016, 05:08 PM
This is my very first submission to Dynamic Drive, have used the website since 2005 and been very useful to me over the years and thought id contribute some code my self.

The following is a Talking Clock (Or SpeakingClock as some people know the service to be)
This makes use of the speechSynthesis DOM element in newer browsers of Chrome and Firefox, and im lead to believe this also is available on iOS browsers.
I believe it does not work for IE browsers (Rolls eyes as usual, good old Microsoft)

This is my first version and is what id consider a rough draft, I worked on it last night and had it running thru out the day reading the correct times.

Traditional speaking clocks using TTS read the time as 16:45 (Sixteen Forty Five)
This clock reads the time as a person would usually tell a friend, ie 16:45 = Quarter to Five, 00:00 = Midnight

The time interval can be adjusted and you can set it to read out as frequent as you want, (Not easy at the moment as this is my first draft) but in time id like to update it once ive made it more jazzy and easier to blend into some ones existing webpage or even have variables that pass that make it easy to configure and set.

For now if this gets approved, my name is Adam MacKay (UK).
Thanks you
Enjoy and hopefully you guys like it

Revision follows beneath....

01-24-2016, 03:26 AM
Revision: Version 1.2

What is new?

* Error Detection
* HTML 5 Audio for Beeps (when enabled)
* Translation
Previously you could configure the settings to spanish ie: es-ES for the isoLangCode, but it would only read the text as is, for instance "The time is:" would still be "The Time is" just with a spanish reader.
The new version has had efforts made to cover 4 languages (Spanish, English, French, German) or en-US, en-GB, es-ES, fr-FR, de-DE.

* 4 Modes

Millitary (Zero 800 hours) 08:00
Basic (08:01) = eight: zero one
Friendly (08:45) = quarter to nine
Talking Clock = at the next stroke, the time sponsored by accurist will be 8, 45, precisely

Previously settings was just variables, now the JS file contains 2 main objects
* Config

Settings can now be added to the page as follows

<script type="text/javascript" src="talkingClock.js"></script>
Config.testing = false;
Config.testTime = "00:00:00";
Config.refreshRate = 100;
Config.readOutFrequency = 1;
Config.repeatTimePerMinute = 4;
Config.volume = 100;
Config.readStyle = 2;
Config.prefix = "The time now is:";
Config.suffix = "";
Config.dayState = false;
Config.includeSeconds = true;

TTS.grabVoices = 10;
TTS.voiceToUse = 4;
TTS.isoLangCode = "de-DE";
TTS.enableBeeps = true;
TTS.beeper = TTS.beeperMP3Path;


Default values
Error detection

Time of the day:
ie: if the time is before mid-day the time will have "in the morning" appended to the reading

01-25-2016, 12:41 AM
Some minor bugs repaired

Compared to the first release 3 days ago, the script has been entirely re-written
Whats new?

* Languages is now an array rather than a switch statement, making the script shorter and easier to configure (Current languages: German, English, French, Spanish)
* Config and TTS objects created
* Error Handling
* 4 Styles (Millitary, Basic, Friendly, TalkingClock style)
* Bug fix to: Testing, Midnight readings, 10 minutes past readings
* Beeps (MP3 recording of cordless phone beep)

Simply replace the existing javascript file with the one included in the attachment