Talking clock on old laptop or an Android app

Viewed 17

I want to program a "talking clock" for my blind father and I have an very old laptop, 768 RAM. I have tried many different things, from making an app on android with kivy, without any success, because on my laptop (a different one) seems to work like a charm but when I'm "buildoze" it just doesn't play any mp3. I've tried some answers provided on SO with no success. Now I thought to try to install different things, like Python libraries for 2.79 and even Java on my old laptop, but seems that because Linux Mint 2.0 it's no longer supported can't install anything...

Does anyone have any suggestion if I can use that old laptop for such a thing or I can make an app for Android that plays mp3's?

I quite a noobie

Thanks

2 Answers
  • Here's a speaking-clock in JS - just load it into a WebView or something - but you don't even need to package an app: just put it in a HTML page with a PWA manifest and save that as a home-screen icon so it will work while offline.

  • Click "Run code snippet" and then the button.

  • It will work in any modern web-browser available for Android and Linux desktops (except Opera and the stock (non-Chrome) Android Browser - it will also work in any modern Linux desktop environment - or any desktop OS, really.

  • I hope the code is self-explanatory.

    • It uses the Web Speech Synthesis API which is widely supported (except by the not-Google-Chrome Android Browser for some reason).
  • Note that it is not possible to make it play automatically or on-load (so need to click the button first to make speech synthesis work), as most browsers (including Chrome) block scripts from auto-playing sounds without user-interaction; the same applies to <video>, <audio>, etc.

Eta voila:

function sayTime() {

    if( window.speechSynthesis.speaking ) return;

    const now = new Date();
    
    var tts = new SpeechSynthesisUtterance();
    tts.text = "The time is now " + now.toLocaleTimeString();
    
    window.speechSynthesis.speak( tts );
}

let timerId = null;

function toggleSpeakingClock() {

    if( timerId ) {
        window.speechSynthesis.cancel();
        window.clearInterval( timerId );
        timerId = null;
        btn.textContent = "Click me to start";
    }
    else {
        timerId = window.setInterval( sayTime, 1000 );
        const btn = document.getElementById('btn');
        btn.textContent = "Click me to stop";
    }
}

document.addEventListener( 'DOMContentLoaded', function() {
  
  const btn = document.getElementById('btn');
  btn.disabled = !( typeof window.speechSynthesis === 'object' ) && ( window.speechSynthesis !== null );
  if( btn.disabled ) btn.textContent = "Your browser doesn't support TTS";

} );
<button id="btn" onclick="toggleSpeakingClock()" disabled>Please wait...</button>

Quick, dirty, and simple: install espeak and run something like the following in a cron job as often as you like:

dt=$(date +'%A, %B %d, %Y. The time is %l %M %p.'); espeak "Today is $dt"

EDIT: On reflection, It might be better to write a shell script and call that from cron. Assuming your father's only challenge is blindness, he probably doesn't need to be reminded of the date every, say, fifteen minutes. A script could speak the date every eight hours, perhaps, and the time as often as is useful.

EDIT AGAIN: Here's a script I threw together for fun. Give it a try.

#!/bin/bash
# If espeak isn't installed, complain and quit
command -v espeak > /dev/null 2>&1 ||\
    { echo -e "$0 requires espeak to be installed. Exiting..." ; exit 1; }

# ** Set variables
date_now=$(date +'%A, %B %d, %Y')
military_time=$(date +'%R') # 24-hour time
minute=$(date +'%M')

# We don't need espeak to say "zero zero" for the minutes
if [ $minute = "00" ]; then
    time_now=$(date +'%l %p')
else
    time_now=$(date +'%l %M %p')
fi

# Speak the date only if it's 9am or 5pm
[[ $military_time = "09:00" || $military_time = "17:00" ]] && espeak "Today is $date_now."

espeak "The time is $time_now."
Related