Converting ASCII Text to CW Morse Code with Linux
453 words | Posted by Scott on February 2nd, 2010
Scott was 24.36 years old when he wrote this!
Filed under: General, Linux, Python, Radio
I wanted a way to have a bunch of Morse code mp3s on my mp3 player (with a WPM/speed that I decide and I found an easy way to do it with Linux. Rather than downloading existing mp3s of boring text, I wanted to be able to turn ANY text into Morse code, so I could copy something interesting (perhaps the news? hackaday? bash.org?). It’s a little devious, but my plan is to practice copying Morse code during class when lectures become monotonous. [The guy who teaches infectious diseases is the most boring person I ever met, I learn nothing from class, and on top of that he doesn't allow laptops to be out!] So, here’s what I did in case it helps anyone else out there…
Step 0: GET THE REQUIRED PROGRAMS! Yes, there’s a step zero. Make sure you have installed Python, cwtext, and lame. Now you’re ready to roll!
Step 1: PREPARE SOME TEXT! I went to Wikipedia and copy/pasted an ENTIRE article into a text file called in.txt. Don’t worry about special characters (such as ” and * and #), we’ll fix them with the following python script.
import time
f=open("out.txt")
raw=f.read()
f.close()
cmd = """echo "TEST" | cwpcm -w 7 | """
cmd += """lame -r -m m -b 8 --resample 8 -q9 - - > text.mp3"""
import os
i=0
for chunk in raw.split("\n")[5:]:
if chunk.count(" ")>50:
i+=1
print "\n\nfile",i, chunk.count(" "), "words\n"
do = cmd.replace("TEST",chunk).replace("text","%02d"%i)
print "running:",do,
time.sleep(1)
print "\n\nSTART ...",
os.system(do)
print "DONE"
Step 2: MAKE MP3s OF THE TEXT! There should be a new file, out.txt, which is cleaned-up nicely. Run the following script to turn every paragraph of text with more than 50 words into an mp3 file…
f=open("out.txt")
raw=f.read()
f.close()
cmd = """echo "TEST" | cwpcm -w 13 | sox -r 44k -u -b 8 -t raw - text.wav"""
cmd+="""; lame --preset phone text.wav text.mp3; rm text.wav"""
import os
i=0
for chunk in raw.split("\n")[5:]:
if chunk.count(" ")>50:
i+=1
print i, chunk.count(" "), "words"
os.system(cmd.replace("TEST",chunk).replace("text","%02d"%i))
Now you should have a directory filled with mp3 files which you can skip through (or shuffle!) using your handy dandy mp3 player. Note that “-w 13″ means 13 WPM (words per minute). Simply change that number to change the speed.
Good luck with your CW practice!
–Scott (AJ4VD)
This entry was posted on Tuesday, February 2nd, 2010 at 10:58 amand is filed under General, Linux, Python, Radio. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
2 Responses to “Converting ASCII Text to CW Morse Code with Linux”
| :) wrote the following at 12:47:50 PM on May 4th, 2010 |
|
Thanks! |
| Jim wrote the following at 03:25:55 PM on August 14th, 2010 |
|
Scott, I LIKE this. I’m going to try it out. Will help me with increasing my code speed & comprehension. |