<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="../gus_xslt.xsl"?>
<gus_xslt
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://starling.ws/XML/gus_xslt.xsd">
<head>
  <navigation ToC="Table of Contents" 
    section="yes" topic="yes" subtopic="yes" subsubtopic="yes" links="yes"/>
  <syndication atom="http://starling.us/starling_us_atom.xml" />
  <cgi img="no" img_action="../cgi-bin/gus_web_photo.pl" img_path="../morse/" />
  <pdfmarks body="no" section="no" topic="no" subtopic="no" subsubtopic="no"/>
  <title>Morse Code</title>
  <description>Morse code practice program</description>
  <keywords>ky8d, perl, cw, morse code, amateur radio, ogg vorbis</keywords>
  <author>Gan Uesli Starling</author>
  <copyright>2006, Gan Uesli Starling</copyright>
</head>
<body>
  <title>KY8D Morse Code Perl Script</title>
  <p>When it came time to renew my Extra Class ham radio license I was chagrined to realize that my copy speed in CW has slipped to down around 13 WPM for plain English. Forgotten entirely were the six extra letters for Esperanto and obscure punctuation marks and prosigns. So I wrote my own Morse code (re)trainer program to use with my favorite MP3 player.</p>

  <section>
    <title>Audio file generator</title>
    <p>Other free Morse code practice programs play through the MIDI device of your sound card. That, of course, ties you to your computer. Mine writes out audio files in<code> *.wav </code>format, optionally converting these into<code> *.ogg </code>format. This way frees you to play them out of any worthwile MP3 player.</p>
    <p><b>Download: </b>
       <a class="button" 
         title="gus_morse.pl version 2006-03-05 17:50:00 Z" 
         href="./gus_morse.txt">&#160;Perl&#160;
       </a>&#160;
       <a class="button" title="gus_morse.exe" href="./gus_morse.exe">&#160;Win32&#160;</a>&#160;
       <a class="button" title="Documentation" href="./gus_morse.html">&#160;POD&#160;</a>&#160;       
    </p>
    <topic>
      <title>On Unix/Linux/BSD/OS&#160;X</title>
      <p>Remember to adjust the path in the <code>shebang</code> line. I have it set for NetBSD. Your&#8217;s might vary slightly. You very likely already have Perl, but in addition need to acquire these Perl modules:<code> Audio::Wav </code>and<code> Time::HiRes</code>. Obtain those in the usuall way from<code> CPAN</code>,<code> pkgsrc</code>, or wherever.</p>
    </topic>
    <topic>
      <title>On Windows</title>
      <p>There are two ways to go, with and without the Perl interpreter.</p>
      <subtopic>
        <title>With Perl</title>
        <p>If you already have the Perl interpreter, then you already know to rename from <code>*.txt</code> to <code>*.pl</code> after downloading the script. You&#8217;ll also know how to obtain the required<code> Audio::Wav </code>and<code> Time::HiRes </code>modules care of<code> PPM </code>or<code> CPAN </code>or wherever.</p>
      </subtopic>
      <subtopic>
        <title>Sans Perl</title>        
        <p>For the Perl impoverished I&#8217;ve also provided a standalone<code> *.exe </code>version care of Perl PAR. If you have no need of running any other Perl scripts, then choose this. Just know that I may not update this version as often as the script because I need to be on a Win32 machine in order to generate it. At home I run NetBSD Unix, not Windows. So updates to<code> gus_morse.exe </code>may lag behind those of<code> gus_morse.pl </code>and its accompanying documentation.</p>
        <p>If you&#8217;d like to obtain the Perl interpreter, a later section of this page will tell about that.</p>
      </subtopic>
    </topic>
  </section>
  
  <section>
    <title>Audio files &amp; tagged text</title>
    <p>Here are some example Morse code audio files created using my <code>gus_morse.pl</code> Perl script. Provided only as example output, most are arranged for my own convience as follows:</p>
    <ul>
      <li><b>First file: </b>18 or 20 WPM chars spaced at 5/10ths of WPM rate (Farnsworth method).</li>
      <li><b>Later files: </b>Spacing approaches WPM rate by increments (6/10ths&#160;... 10/10ths). </li>
      <li><b>Final files: </b>Chars &amp; spacing increase, slightly, beyond 20 WPM</li>
   </ul>
   <p>You may easily reformat any of them for different WPM rates and spacings. Just download the pure ASCII, asterisk-tagged text and edit their embeded<code> *wpm=20* </code>tags. Then generate your own<code> *.wav </code>or<code> *.ogg </code>files according to personal preference via my free<code> gus_morse.pl </code>Perl script. Refer to included documentation <note>(POD as HTML)</note> for details on not quite self-evident usage of<code> *koch=1*</code>, <code> *diff=5*</code>, <code> *rand=1* </code>and<code> *next* </code>tags.</p>
    <topic>
      <title>English</title>
      <p>Some text files and the results of their conversion into Morse code as audio files.</p>
      <p><a class="button" href="./typing_drills/">Ogg Vorbis</a>&#160;
         <a class="button" href="./typing_drills/typing_drills.txt">ASCII Text</a>&#160;
         Alphabetic-sentence typing drills       
         <br/><a class="button" href="./PG_17192/">Ogg Vorbis</a>&#160;
         <a class="button" href="./PG_17192/PG_17192.txt">ASCII Text</a>&#160;
         <i>The Raven</i> &#8212; by Edgar Allen Poe 
      </p>
    </topic>
    <topic>
      <inlink>esperanto</inlink>
      <title>Esperanto</title>
      <p>Kelkaj teksto-dosieroj kaj la rezultoj post ilia ŝanĝiĝo al Morsa kodo kiel sondosieroj.</p>
      <p><a class="button" href="./cxapelitoj/">Ogg Vorbis</a>&#160;
        <a class="button" href="./cxapelitoj/cxapelitoj.txt">ASCII Text</a>&#160;
        Ĉapelitoj sendataj laŭ la metodo de Koch.
        <br/><a class="button" href="./interpunkcioj/">Ogg Vorbis</a>&#160;
        <a class="button" href="./interpunkcioj/interpunkcioj.txt">ASCII Text</a>&#160;
        Interpunkcioj sendataj laŭ la metodo de Koch.
        <br/><a class="button" href="./PG_17425/">Ogg Vorbis</a>&#160;
        <a class="button" href="./PG_17425/PG_17425.txt">ASCII Text</a>&#160;
        <i>La Falo de Uŝero-Domo</i> &#8212; de Edgar Allen Poe
      </p>
    </topic>
  </section>

  <section>
    <title>Whole books as CW</title>
    <p>Since alphabetic typing drills grow wearisome in very short order, where should you look to obtain more interesting material with which to feed my<code> gus_morse.pl </code>Perl script? For the Edgar Allan Poe material cited above, in both English and Esperanto, I went to the Gutenberg Project. They have thousands more, whole books even, available for free download. Here is a link:&#160;<a href="http://www.gutenberg.org/">Gutenberg</a></p>
  </section>

  <section>
    <title>Auxilliary tagging script</title>
    <p>Included herewith is an auxilliary Perl script,<code> gus_morse_tagger.pl </code>to auto-insert the the special asterisk-delimited tags looked for by the main<code> gus_morse.pl </code>Perl script. Use it incombination with arbitrarily large, plain ASCII, text files to render an entire book into any quantity of sequentially-numbered audio files.</p>
    <p><b>Download: </b>
       <a class="button" 
         title="gus_morse_tagger.pl version 2006-03-05 17:50:00 Z" 
         href="./gus_morse_tagger.txt">&#160;Perl&#160;</a>&#160;
       <a class="button" 
         title="gus_morse_tagger.exe" 
         href="./gus_morse_tagger.exe">&#160;Win32&#160;</a>&#160;
       <a class="button" 
         title="Documentation" 
         href="./gus_morse_tagger.html">&#160;POD&#160;</a>
    </p>
    
    <p>Below is an extreme example of the two scripts used in combination. Input file is A. Merritt&#8217;s <i>The Moon Pool</i>, from The Gutenberg Project (catalog item 765), obtained as US-ASCII. Manual pre-processing was minimal, involving only these steps...</p>
    <ol>
      <li>Stripping out the project&#8217;s tack-on header &amp; trailer</li>
      <li>Inserting a<code> *next* </code>tag at start of each chapter.</li>
    </ol>
    <p>...the results of which I renamed as<code> PG_765.txt </code>and feed into the tagger Perl script as you see below. The output of that I feed into the main Perl script. For clarity, note that commands show as black, system feedback as<span style="color:darkred;"> dark red </span>and insertions of ex-post-facto commentary as<span style="color:teal;"> teal</span>. Elipsis (<span style="color:teal;">...</span>) indicates lines of system feedback not shown.</p>
    
<pre>baal: {666} <cmd>perl gus_morse_tagger.pl -p PG_765.txt -s 22 -d 8 -f 30 -c 750</cmd>
Inserting *next* into PG_765.txt approximately every 750 characters.
Output = PG_765_morse.txt.
File breaks: Original = 36 Inserted = 572 <note>(Meaning the script added 572 *next* tags to the 36 I&#8217;d already put in.)</note>
All done.
baal: {667} <cmd>perl gus_morse.pl -p PG_765_morse.txt -c ogg</cmd>
Running gus_morse.pl version 2006-03-05 17:50:00 Z 
File = "PG_765_morse_001.ogg"
Speed = 22.000 WPM chars @ 17.600 WPM spacing
Date = 2006-03-05 18:31:40.20177 Z
Opening with wav module: WAV file reader
Encoding "PG_765_morse_001.wav" to 
         "PG_765_morse_001.ogg" 
at quality 3.00
        [100.0%] [ 0m00s remaining] \

Done encoding file "PG_765_morse_001.ogg"

        File length:  13m 29.0s
        Elapsed time: 0m 04.9s
        Rate:         166.8586
        Average bitrate: 5.7 kb/s

<note>...and so on, with spacing converging slowly upon character speed until...</note>

File = "PG_765_morse_608.ogg"
Speed = 30.000 WPM Date = 2006-03-06 05:33:26.536554 Z
Opening with wav module: WAV file reader
Encoding "PG_765_morse_608.wav" to 
         "PG_765_morse_608.ogg" 
at quality 3.00
        [100.0%] [ 0m00s remaining] /

Done encoding file "PG_765_morse_608.ogg"

        File length:  4m 44.0s
        Elapsed time: 0m 01.6s
        Rate:         182.6837
        Average bitrate: 6.2 kb/s

All done.
baal: {668}</pre>
    <p>The above process was left to run overnight on a very fast PC under NetBSD 2.0.2 (Unix)&#160;OS but which was burdened with the overhead of hosting of five network servers: Apache, PostgreSQL, XML-RPC, Entropy/RSA and TOR. Thus it still took just under 12 hours to crank out 608<code> *.wav </code>files and convert them to an equal number of<code> *.ogg </code>files eventually totalling 393MB.</p>
    <p>I did say that it was to be an extreme example. I certainly have my listening cut out for me. But if that does not get me back to 25 WPM and beyond then I had ought to admit defeat, dust off my microphone and design new QSL cards. Or as would more likely be the case, sell my radios and abandon the hobby forever since CW was the only real fun I ever got out of it when I had used to be more active.</p>
    <p>Win32 folks may wish to know that, just for grins, I likewise perfromed a slightly faster run on a two-years older Win2K PC without a RAM disk for almost as many files but without the added burden of its having to serve umpteen network clients at the same time.</p>
  </section>

  <section>
    <title>MP3 player support</title>
    <p>All MP3 devices of any merit will play out<code> *.wav </code>files. Many of the better ones will also play<code> *.ogg </code>files. No few support additional formats such as<code> FLAC</code>,<code> AIFF</code>,<code> WMA</code>,<code> ASF </code>and others. Not all support Ogg&#160;Vorbis...yet. But if your player has plenty RAM then the large size of<code> *.wav </code>files won&#8217;t be a burden.</p>
    <p>Currently, my script only writes to the<code> *.wav </code>and<code> *.ogg </code>formats. Why&#8217;d I go and leave out<code> *.mp3</code> then? The answer is that Ogg&#160;Vorbis is a general purpose audio and music encoding format contemporary to MPEG-4&#8217;s AAC and TwinVQ, the next generation beyond MPEG audio layer 3. Unlike the MPEG sponsored formats (and other proprietary formats such as RealAudio G2 and Windows&#8217; flavor of the month), the Vorbis CODEC specification belongs to the public domain. All the technical details are published and documented, and any software entity may make full use of the format without royalty or patent concerns.</p>
    <p>Compare to this the twin facts that: (A) The German company Faunhofer owns patents on MP3. They charge money and sue vendors who do not pay; and (B) For equivalent file sizes, Ogg&#160;Vorbis sounds notably better than MP3.</p>
    <p>An ever-increasing number of so-called <i>MP3 players</i> already support plural formats, WAV and Ogg Vorbis most common among them. A growing number of older players offer plug-in upgrades to Ogg&#160;Vorbis on their websites. And while there are still a few holdouts, that may change as time goes by if only for economic reasons. Read more here:&#160;<a href="http://vorbis.com">HTML</a>, <a href="http://www.mondodesigno.com/music/ogg.html">HTML</a> &amp;&#160;<a class="button" href="http://george.hotelling.net/90percent/digital_music/howto_how_and_why_you_would_want_to_get_ogg_vorbis_on_itunes.php">HTML</a></p>
    <p>If still not convinced, please feel free to convert from<code> *.wav </code>to<code> *.mp3 </code>on your own.</p>
    
    <topic>
      <title>Player hardware</title>
      <p><a href="http://onlinestore.cowonamerica.com/">HTML</a>&#160;Cowon makes the model I like best, the IAudio5 with 2GB RAM. I&#8217;ve had it now for most of a year. I&#8217;ve dropped it to the floor a few times without any damage. Liked it so well I bought one for my sister. She then bought one for her husband.
      <br/><a href="http://wiki.xiph.org/index.php/PortablePlayers">WIKI</a>&#160;Here is a Wikipedia page of Vorbis-enabled portable players.</p>
    </topic>   
    <topic>
      <title>Unix/Linux/BSD/OS&#160;X software</title>
      <p>You may already set up for Ogg Vorbis. If not, just install the<code> libvorbis </code>and<code> vorbis-tools </code>software packages in whatever way is usual for your platform.</p>
    </topic>
    <topic>
      <title>Windows software</title>
      <p><b>Encode: </b>To write Ogg Vorbis files you will need one or another of the<code> oggenc </code>clones. Here is one:&#160;<a class="button" href="http://www.rarewares.org/dancer/dancer.php?f=53">ZIP</a>&#160;Download and install into<code> C:\&#160;</code>directory as<code>&#160;C:\oggenc2.exe </code></p>
      <p><b>Decode: </b>To play Ogg Vorbis choose from any of the ways described here: <a href="http://www.vorbis.com/setup_windows">HTML</a></p>
    </topic>
  </section>

  <section>
    <title>Obtaining Perl for Win32</title>
    <p>Perl scripts are platform independent. They do require an interpreter though, quite the same as scripts for BASIC, Python, Ruby, etc. The Perl interpreter is totally free and nearly always comes pre-installed on Unix, Linux, BSD and Mac&#160;OS&#160;X. Those folks will be familiar and require no explanations.</p>
    <p>Windows folks, however, will need to obtain the Perl interpreter. The process is brain-dead simple, but may require an administrative password on WinNT, Win2K and WinXP.</p>
    <p>Here is where to get Perl for Windows:&#160;<a href="http://www.activestate.com/Products/ActivePerl/">Download&#160;Page</a>&#160;<a href="http://aspn.activestate.com/ASPN/docs/ActivePerl/install.html#installing%20activeperl%20on%20windows%20(x86)">Installation&#160;Doc</a></p>
    <topic>
      <title>Perl Modules</title>
      <p>Perl has many useful features bundled as separate <i>modules</i> of code. Many are already built in. A great many more, usually for exotic tasks, require installation before use. My script makes use of two such exotics. Perl itself will fetch these for you. All you need do is open a DOS window and type these commands:</p>
      
<pre>C:\&gt; <cmd>ppm</cmd>
PPM&gt; <cmd>install Audio::Wav</cmd>
<note>... (Note: Elipsis indicates feedback lines not not shown)</note>
PPM&gt; <cmd>install Time::HiRes</cmd>
<note>...</note>
PPM&gt; <cmd>exit</cmd>
C:\&gt;</pre>

      <p>Pause slightly after each<code> install </code>line to let Perl fetch your request from official Perl repositories on the Internet. Then give the<code> exit </code>command. The DOS prompt will return. Lastly double check that all went well by by typing this.</p>
      
<pre>C:\&gt; <cmd>perl -e "use Audio::Wav; use Time::HiRes;"</cmd>
C:\&gt; </pre>

      <p>If nothing whatever seems to happen, as above, then all is well. Type<code> exit </code>again to close the DOS window.</p>
    </topic>
  </section>

  <section>
    <title>RAM disk</title>
    <p>It is often more convenient (and faster) to work inside a virtual drive (<code>RAM disk</code>) when composing audio files. On my NetBSD Unix box, I create a RAM disk at boot by having this line in my <code>/etc/rc.local</code> file.</p>    
    <p style="text-align:center;"><code>mount_mfs -s 900m swap /ram</code></p>    
    <p>For Linux or Mac OS X that method may differ slightly. You can also do it for Win32, but I have long since forgotten how.</p> 
    <p>Note that before writing <code>gus_morse.pl</code> I already had a RAM disk in place, and that my own is a whopping 900MB on account of I enjoy 4GB system RAM. I use so large a RAM disk mainly for converting whole CDROM&#8217;s first to <code>*.wav</code> using <code>cdparanoia</code> and then to <code>*.ogg</code> using <code>oggasm</code>. Converting them to <code>*.ogg</code> at Q2 lets me stuff entire audio books (20-25 CDROM&#8217;s each) onto one CDROM. I can then download five or more such books into my tiny Cowon IAudio5 2GB MP3 player (far superior to an I-Pod in my estimation). This is the only way to alleviate the tedium of my 1-hour commute to and from work every day.</p> 
  </section>

  <section>
    <title>To do list</title>
    <p>A further thing I would like to do is to support more languages than just English and Esperanto.</p>
    <p>I am currrently looking into some way of writing direct to Ogg&#160;Vorbis so as to eliminate the conversion delay for when that option is chosen. I am assured by the Vorbis gurus that this method would be very fast indeed, faster even than to<code> *.wav</code>.</p>
    <p>After all those, who knows, maybe I&#8217;ll even add a GUI.</p>
    <p>A very tentative future item is to implement an over-the-Internet Morse code communication system similar to Morse Mail but with send &amp; receive occuring in realtime just like radio. Don&#8217;t hold your breath, though, as it is sure to take quite a while. I have even yet to decide whether to use XML-RPC or streaming Ogg&#160;Vorbis as the transport. So far all I&#8217;ve accomplished is to make this present script output a quasi-Morse Mail textual format encoding mark and space as miliseconds in XML.</p>
  </section>

  <section>
    <title>Last resort</title>
    <p>If all other methods fail you I might be persuaded to supply custom Morse code drills on request. To stem a potential flood of requests, I will first have to agree via email. Having agreed, I will further require that a minimum of $5 USD be paid into my PayPal account <span style="color:darkgreen">(krom se oni petas E-lingve)</span>. That much agreed, I could create custom files of user-supplied text at requested speeds, etc, and place the (doubtless very large) audio files into a temporary directory on my website for downloading. For a more significant bribe I might trouble to send the results via snail mail on CDROM.</p>
    <p>I&#8217;m sure you would rather do for yourself. It is easy enough after all. But if nothing else affords, then as a last resort explain your situation to me via email at&#160;<a class="button" href="mailto://gan@starling.us">gan@starling.us</a></p>
  </section>

</body>
</gus_xslt>
