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.
Encode a text string into Morse code.
string
: The text string you want to encode.language
: The target language for encoding ( e.g.,english
,french
,spanish
,russian
,ukranian
,numbers
,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 character is encountered (default is*
).
from MorseCodePy import encode
encoded_string = encode('Hello, world!', language='english')
print(encoded_string)
# Output: .... . .-.. .-.. --- --..-- / .-- --- .-. .-.. -.. -.-.--
from MorseCodePy import encode
encoded_string: str = encode('10 pièces !', language='french')
print(encoded_string)
# Output: .---- ----- / .--. .. .-..- -.-. . ... / -.-.--
Decode Morse code into a text string.
code
: The Morse code string you want to decode.language
: The target language for decoding ( e.g.,english
,french
,spanish
,russian
,ukranian
,numbers
,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
decoded_string = decode('···· · ·-·· ·-·· --- --··-- / ·-- --- ·-· ·-·· -·· -·-·--', language='english', dot='·')
print(decoded_string)
# Output: hello, world!
Play Morse code sound.
code
: The Morse code you want to play.delay
: (optional) The delay in seconds between characters (default is 0.5).volume
: (optional) The volume of the Morse code playback (default is 1.0).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, play
encoded_string: str = encode('Hello', language='english')
play(encoded_string, delay=0.5, volume=0.8)
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(dot='·')