Skip to main content

Easily and correctly encode and decode text into Morse code

Project description

MorseCodePy

Python Version Pygame Version

Introduction

MorseCodePy is a versatile Python module that streamlines the encoding and decoding of text into Morse code and back. With support for multiple languages, including English, Russian, Ukrainian Spanish, French, as well as provisions for handling numbers and other special characters, this module offers a powerful and user-friendly Morse code tool. Whether you want to send messages, decipher existing ones, or simply explore the world of Morse code, MorseCodePy has you covered.


How to Use

encode(string, language, dot, dash, error)

Encode a text string into Morse code.

  • string: The text string you want to encode.
  • language: The target language for encoding (e.g., Language.english, Language.french, Language.numbers).
  • dot: (optional) Symbol to represent dots (default is .).
  • dash: (optional) Symbol to represent dashes (default is -).
  • error: (optional) Symbol to represent errors when an unknown character is encountered (default is *).
from MorseCodePy import encode, Language

encoded_string = encode('Hello, world!', language=Language.english)
print(encoded_string)
# Output: .... . .-.. .-.. --- --..-- / .-- --- .-. .-.. -.. -.-.--

decode(string, language, dot, dash, error)

Decode Morse code into a text string.

  • string: The Morse code string you want to decode.
  • language: The target language for decoding (e.g., Language.russian, Language.spanish, Language.special).
  • dot: (optional) Symbol to represent dots (default is .).
  • dash: (optional) Symbol to represent dashes (default is -).
  • error: (optional) Symbol to represent errors when an unknown Morse code sequence is encountered (default is *).
from MorseCodePy import decode, Language

decoded_string = decode('···· · ·-·· ·-·· --- --··-- / ·-- --- ·-· ·-·· -·· -·-·--', language=Language.english, dot='·')
print(decoded_string)
# Output: hello, world!

Language

The Language enumeration represents different languages, including special cases for numbers and special characters. Use it to specify the language when encoding or decoding Morse code.

Supported languages include Language.english, Language.spanish, Language.french, Language.russian, Language.ukrainian, as well as special categories for handling Language.numbers and Language.special.


chart(dot, dash)

Print a Morse code chart in the console.

  • dot: (optional) Symbol to represent dots (default is ·).
  • dash: (optional) Symbol to represent dashes (default is -).
from MorseCodePy import chart

chart()
# Output: Morse Code Chart: ...

play(code, delay, dot, dash, separator)

Play Morse code sound.

  • code: The Morse code you want to play.
  • delay: (optional) The delay in seconds between characters (default is 0.4).
  • dot: (optional) Symbol to represent dots (default is .).
  • dash: (optional) Symbol to represent dashes (default is -).
  • separator: (optional) Symbol to represent separators (default is /).
from MorseCodePy import encode, Language, play

encoded_string: str = encode('Hello', language=Language.english)

play(encoded_string, delay=0.5)

To use the sound functionality of MorseCodePy, you'll need the dot.wav and dash.wav sound files. These files are not included in the module's distribution and must be sourced separately.

Follow these steps to obtain and configure the sound files:

  1. Obtain Sound Files: You can download existing files or create dot.wav and dash.wav sound files in .wav format.
  2. Placement: Place the dot.wav and dash.wav files in a directory called sounds/ in your project.

Once you have obtained and placed the sound files as specified, you'll be able to use the sound playback features of MorseCodePy.


encodes and decodes

These dictionaries contain Morse code representations for various languages and characters. You can access these dictionaries to customize the encoding and decoding behavior.

import MorseCodePy as mcp

english_encoding = mcp.encodes[mcp.Language.english]
russian_decoding = mcp.decodes[mcp.Language.russian]

Explore and adapt MorseCodePy for your specific needs.


Licence

This project is licensed under the MIT License. See the Full Licence for more details.


Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MorseCodePy-2.1.2.tar.gz (6.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page