A Python 3 command-line application that converts text ↔ Morse code with optional 700 Hz audio playback.
| 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).
# 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 --helpMultiple words can be passed without quotes:
python morse.py encode Hello World # same as "Hello World"
python morse.py decode ... --- ... # same as "... --- ..."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┌─ Input (Text) ──────────────────────────────────────────
│ Text:
│ Hello World
├─ Output (Morse) ────────────────────────────────────────
│ Morse:
│ .... . .-.. .-.. --- / .-- --- .-. .-.. -..
└─────────────────────────────────────────────────────────
Long values are word-wrapped to fit within the box.
| Symbol | Meaning |
|---|---|
. |
Dot |
- |
Dash |
|
Letter separator (single space) |
/ |
Word separator (space-slash-space) |
| Category | Characters |
|---|---|
| Letters | A–Z (case-insensitive) |
| Digits | 0–9 |
| Punctuation | . , ? ! - / @ ( ) |
Audio is generated entirely in Python (wave + struct + math.sin) and piped to a system player. No Python audio library is required.
| 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) |
| Platform | Player used |
|---|---|
| Linux | ffplay → aplay → paplay → sox (first found) |
| macOS | ffplay → afplay |
| 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-inmorse-py/
├── morse.py Single-file application (encode, decode, audio, CLI)
├── test_morse.py pytest / unittest test suite (32 tests)
└── README.md