A compact, feature-rich Morse Code ⇄ Text translator with CLI, GUI, and REST API. Bidirectional conversions for letters, numbers, and common punctuation with built-in validation.
- Text ↔ Morse: bidirectional conversion for A–Z, 0–9, and common punctuation
- Validation: checks Morse syntax (allowed:
.,-,/, space; max 6 chars per token) - Interactive CLI: menu-driven experience via
main.py - Desktop GUI: responsive
customtkinter-based UI with text/Morse input fields and toggle switch - REST API: FastAPI with versioned routes (
/v1) and interactive docs at/docs - Installable package: global
morsecommand afterpip install -e . - CLI flags: single-shot conversions (
-t,-m,-vm,-ui)
- Clone and create virtual environment:
git clone https://github.com/amirhossein77-98/Morse-Translator.git
cd Morse-Translator
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -e .Installs the project in development mode with the global morse CLI entry point.
Alternative environments:
- pipenv:
pipenv install --dev && pipenv shell - poetry:
poetry install && poetry shell - uv:
uv sync(if initialized with uv)
Interactive menu:
python3 main.pyAll flags are mutually exclusive. Use / (space-slash-space) to separate words in Morse.
Text to Morse:
python3 main.py -t "Hello World"
morse -t "Hello World" # After pip install -e .Morse to Text:
python3 main.py -m ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."Validate Morse:
python3 main.py -vm ".... . .-.. .-.. ---"Launch the responsive customtkinter GUI:
python3 main.py -ui
morse -ui # After pip install -e .Features:
- Toggle between "Text to Morse" and "Morse to Text" via switch
- Real-time input/output textboxes
- Validation for Morse input
- Responsive grid layout, centered widgets
Start the FastAPI server:
uvicorn api.app:app --reloadOpen http://127.0.0.1:8000/docs for interactive API docs.
Example endpoints (base: /v1):
# GET
curl "http://127.0.0.1:8000/v1/text-to-morse/hello"
curl "http://127.0.0.1:8000/v1/morse-to-text/--"
curl "http://127.0.0.1:8000/v1/validate-morse/--"
# POST
curl -X POST "http://127.0.0.1:8000/v1/text-to-morse" \
-H "Content-Type: application/json" \
-d '{"text":"hello"}'Response format:
{
"original_text": "hello",
"translated_text": ".... . .-.. .-.. ---"
}After pip install -e ., use the global morse command:
morse -t "Hello"
morse -m ".... . .-.. .-.. ---"
morse -vm "..."
morse -uiRun unit and API tests (no server startup needed):
python3 -m unittest discover -v # All tests
python3 -m unittest test.api_tests # API only
python3 -m unittest test.converter_tests # Converter onlyNote: Tests use unittest and FastAPI TestClient. Ensure no stray Unicode characters in test strings.
Build distribution packages:
pip install build
python -m buildCreates wheels and source distributions in dist/.
Project structure:
core/converters.py— conversion logic & validationdata/morse_dataset.py— Morse/ASCII mappingapi/app.py— FastAPI applicationapi/routes/v1.py— versioned endpointsviews/ui/ctkinter_ui.py— GUI withcustomtkintertest/— unit and API tests
Contributing: Bug reports and PRs welcome. Please include repro steps and test cases.
MIT License — see LICENSE for details.




