Skip to content

tauasa/morse-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Morse Code Converter/Player in Python

A Python 3 command-line application that converts text ↔ Morse code with optional 700 Hz audio playback.


Requirements

Tool Version
Python 3.9+

Zero third-party dependencies. All features use the Python standard library (argparse, wave, struct, math, subprocess).

Audio playback requires one system player to be present (see Audio).


Run

# Encode
python morse.py encode "Hello World"
python morse.py encode --play SOS
python morse.py encode -p "Meeting at 3PM"

# Decode
python morse.py decode "... --- ..."
python morse.py decode --play ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."

# Help
python morse.py --help
python morse.py encode --help
python morse.py decode --help

Multiple words can be passed without quotes:

python morse.py encode Hello World        # same as "Hello World"
python morse.py decode ... --- ...        # same as "... --- ..."

Tests

Tests use pytest (recommended) or the standard unittest module.

# With pytest
pip install pytest
pytest test_morse.py -v

# With unittest (no install needed)
python -m unittest test_morse -v

Output format

┌─ Input (Text) ──────────────────────────────────────────
│  Text:
│  Hello World
├─ Output (Morse) ────────────────────────────────────────
│  Morse:
│  .... . .-.. .-.. --- / .-- --- .-. .-.. -..
└─────────────────────────────────────────────────────────

Long values are word-wrapped to fit within the box.


Morse format

Symbol Meaning
. Dot
- Dash
Letter separator (single space)
/ Word separator (space-slash-space)

Supported characters

Category Characters
Letters A–Z (case-insensitive)
Digits 0–9
Punctuation . , ? ! - / @ ( )

Audio playback (--play)

Audio is generated entirely in Python (wave + struct + math.sin) and piped to a system player. No Python audio library is required.

Timing

Symbol Duration
Dot 60 ms
Dash 180 ms
Intra-character gap 60 ms
Inter-letter gap 180 ms
Inter-word gap 420 ms
Tone frequency 700 Hz
Envelope 10 ms ramp-up/down (no clicks)

Player detection (automatic)

Platform Player used
Linux ffplayaplaypaplaysox (first found)
macOS ffplayafplay
Windows PowerShell Media.SoundPlayer (built-in)

If no player is found, --play is silently skipped with a warning. On most systems:

# Linux — install ffmpeg:
sudo apt install ffmpeg       # Debian / Ubuntu
sudo dnf install ffmpeg       # Fedora

# macOS — ffplay is included with ffmpeg:
brew install ffmpeg

# Windows — no action needed; PowerShell is built-in

Project structure

morse-py/
├── morse.py          Single-file application (encode, decode, audio, CLI)
├── test_morse.py     pytest / unittest test suite  (32 tests)
└── README.md

About

Morse Encoder/Decoder in Python

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages