Shell Scripts For Preschoolers

February 10th, 2012

It probably comes as no surprise to anybody that Jacob has had a computer since he was 3. Jacob and I built it from spare parts, together.

It may come as something of a surprise that it has no graphical interface, and Jacob uses the command line and loves it — and did even before he could really read.

A few months ago, I wrote about the fun Jacob had with speakers and a microphone, and posted a copy of the cheat sheet he has with his computer. Lately, Jacob has really enjoyed playing with the speech synthesizer — both trying to make it say real words and nonsense words. Sometimes he does that for an hour.

I was asked for a copy of the scripts I wrote. They are really simple. I gave them names that would be easy for a preschooler to remember and spell, even if they conflicted with existing Unix/Linux commands. I put them in /usr/local/bin, which occurs first on the PATH, so it doesn’t matter if they conflict.

First, for speech systhesis, /usr/local/bin/talk:


#!/bin/bash
echo "Press Ctrl-C to stop."
espeak -v en-us -s 150

espeak comes from the espeak package. It seemed to give the most consistenly useful response.

Now, on to the sound-related programs. Here’s /usr/local/bin/ssl, the “sound steam locomotive”. It starts playing a train sound if one isn’t already playing:


#!/bin/bash
pgrep mpg321 > /dev/null || mpg321 -q /usr/local/trainsounds/main.mp3 &
sl "$@"

And then there’s /usr/local/bin/record:


#!/bin/bash
cd $HOME/recordings
echo "Now recording. Press Ctrl-C to stop."
DATE=`date +%Y-%m-%dT%H-%M-%S`
FILENAME="$DATE-$$.wav"
chmod a-w *.wav
exec arecord -c 1 -f S16_LE -c 1 -r 44100 "$FILENAME"

This simply records in a timestamped file. Then, its companion, /usr/local/bin/play. Sorry about the indentation; for whatever reason, it is being destroyed by the blog, but you get the idea.


#!/bin/bash
case "$1" in
train)
mpg321 /usr/local/trainsounds/main.mp3
;;
song)
/usr/bin/play /usr/local/trainsounds/traindreams.flac
;;
*)
cd $HOME/recordings
exec aplay `ls -tr| tail -n 1`
;;
esac

So, Jacob can run just “play”, which will play back his most recent recording. As something of a bonus, the history of recordings is saved for us to listen to later. If he types “play train”, there is the sound of a train passing. And, finally, “play song” plays Always a Train in My Dreams by Steve Gillette (I heard it on the radio once and bought the CD).

Some of these commands kick off sound playing in the background, so here is /usr/local/bin/bequiet:


#!/bin/bash
killall mpg321 &> /dev/null
killall play &> /dev/null
killall aplay &> /dev/null
killall cw &> /dev/null

Categories: Children & Computing, Debian, Family, Programming

Leave a comment

Comments Feed5 Comments

  1. Joey

    Funny, I have several of the same commands, although mine don’t choo-choo.

    ~/bin/ seems a better location than /usr/local/bin/, unless you’ll be giving him root later. :)

    Reply

    John Goerzen Reply:

    Heh, well there are four accounts on the system, because – yes – Jacob insisted that Oliver should have his own account. And then that Jacob’s favorite stuffed animal (butterfly) and Oliver’s (bear) should have their own accounts. If he gets to the point of being able to hack a shell script, I suppose I will explain cp and $PATH ;-)

    Reply

  2. XMPP for Children | The Changelog

    […] as I mentioned yesterday, Jacob and Oliver enjoy “their” computer, which I recently put on the LAN. The firewall […]

  3. Florian

    Not only was that a good story to read, I also have to thank you for pointing me to mcabber, it really looks decent. Hooray for fallback commandline jabber tool now.

    Reply

  4. A 4-year-old, Linux command line, and microphone | The Changelog

    […] Feb 10, 2012: I have posted the shell scripts behind […]

Leave a comment

 

Feed

http://changelog.complete.org / Shell Scripts For Preschoolers