Script: Text-to-NATO-spelling

Straight KeyIn my morse training adventure on lcwo.net, I hit a slight bump in the road. At Koch lesson 33 (of 40 lessons total), I can’t seem to copy with 90% accuracy, which is the criterea for moving to the next lesson. See my downward trend here. It is partly because of gradually speeding up the Farnsworth timing from 10wpm to 12wpm so I can be on 20wpm at lesson 40. It is also because of shorter, less focussed daily training sessions, I must confess.

LCWO.net progress

I experimented a bit, and it seems I can recognize characters easily at 37wpm, but I can’t form the words and recognize letters at the same time. More accurately: I can’t seem to be able to remember 3 to 5 characters, form a word and listen to new characters at the same time.

To see if this was morse or memory related, I wrote a small program which spells out a text in speech, NATO phonetic alphabet style. I converted some text with it, and proved that my analysis of my own morse problem was correct. This script can also be used to train “word building”, so that’s why I thought I’d share it with you.

As for me, I am going to switch to morse word training on lcwo.net for a while, see if that helps. Here is the code for spelling out a text using Apple’s built-in text-to-speech synthesizer. It takes a single argument as text file:

#!/bin/bash

# The input text file to parse (first argument)
inputfile="${1}"

# (Temporary) files to write
outputfile="${1}.m4a"
lowercase="${1}.lowercase.txt"
tempfile="${1}.spelled.txt"

# clean up in case we crashed last time
rm ${tempfile}
rm ${lowercase}
rm ${outputfile}

# everything to lower case
tr '[:upper:]' '[:lower:]' < "${inputfile}" > "${lowercase}"

# spell all the letters (change or add as needed)
spell=""
while IFS= read -n1 char; do
  case "${char}" in
  "a") spell="${spell}, alpha" ;;
  "b") spell="${spell}, bravo" ;;
  "c") spell="${spell}, Charley" ;;
  "d") spell="${spell}, delta" ;;
  "e") spell="${spell}, echo" ;;
  "f") spell="${spell}, foxtrot" ;;
  "g") spell="${spell}, golf" ;;
  "h") spell="${spell}, hotel" ;;
  "i") spell="${spell}, India" ;;
  "j") spell="${spell}, Juliet" ;;
  "k") spell="${spell}, kilo" ;;
  "l") spell="${spell}, leehma" ;;
  "m") spell="${spell}, Mike" ;;
  "n") spell="${spell}, November" ;;
  "o") spell="${spell}, Oscar" ;;
  "p") spell="${spell}, papa" ;;
  "q") spell="${spell}, Quebec" ;;
  "r") spell="${spell}, Romeo" ;;
  "s") spell="${spell}, Sierra" ;;
  "t") spell="${spell}, tango" ;;
  "u") spell="${spell}, uniform" ;;
  "v") spell="${spell}, Victor" ;;
  "w") spell="${spell}, whiskey" ;;
  "x") spell="${spell}, X-ray" ;;
  "y") spell="${spell}, Yankee" ;;
  "z") spell="${spell}, Zulu" ;;
  "0") spell="${spell}, zero" ;;
  "1") spell="${spell}, one" ;;
  "2") spell="${spell}, two" ;;
  "3") spell="${spell}, three" ;;
  "4") spell="${spell}, four" ;;
  "5") spell="${spell}, five" ;;
  "6") spell="${spell}, six" ;;
  "7") spell="${spell}, seven" ;;
  "8") spell="${spell}, eight" ;;
  "9") spell="${spell}, nine" ;;
  ".") spell="${spell}. period" ;;
  ",") spell="${spell}. comma" ;;
  "=") spell="${spell}, equals" ;;
  "/") spell="${spell}, slash" ;;
  "?") spell="${spell}. questionmark" ;;
  *) if [ -n "$spell" ]; then
	   echo "${spell:2}." >> "${tempfile}";
	   spell="";
	 fi
  ;;
  esac
done < "${lowercase}"

# Take the tempfile, convert it to spoken text.
say -r 250 -v Alex -f ${tempfile} -o ${outputfile}

# Files left for further processing if you like.
ls -l ${inputfile}*

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s