Skip to main content

Encode, decode & play Morse Code easily

Project description

Logo

Version License

Requirements

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.


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(code, language, dot, dash, error)

Decode Morse code into a text string.

  • code: 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!

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)

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.

from MorseCodePy import encode, Language

encoded_string: str = encode('10 pièces !', language=Language.french)

print(encoded_string)
# Output: .---- ----- / .--. .. .-..- -.-. . ... / -.-.--

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()

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-3.3.tar.gz (80.2 kB view details)

Uploaded Source

File details

Details for the file MorseCodePy-3.3.tar.gz.

File metadata

  • Download URL: MorseCodePy-3.3.tar.gz
  • Upload date:
  • Size: 80.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for MorseCodePy-3.3.tar.gz
Algorithm Hash digest
SHA256 405dfd45c766a9b396e752c651df244227ba549d313dba095e3bf511f647ae75
MD5 958d536b0e4ede88d751ca065e52d63f
BLAKE2b-256 169ff2d4be04ac91f3841fc420bd258de67591e53e4735d90b836c96fb7d9e3f

See more details on using hashes here.

Provenance

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