Encode, decode & play Morse code easily
Project description
Requirements
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.
Usage
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.,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(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.,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_pygame(code, /, delay, volume, *, dot, dash, separator)
Play Morse code sound using pygame
.
code
: The Morse code you want to play.delay
: (optional) The delay in seconds between characters (default is 0.3).volume
: (optional) The volume of the Morse code playback (default is 0.5).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_pygame
encoded_string: str = encode('Hello', language='english')
play_pygame(encoded_string, delay=0.5, volume=0.8)
play_sounddevice(code, /, delay, volume, *, dot, dash, separator)
Play Morse code sound using sounddevice
.
code
: The Morse code you want to play.delay
: (optional) The delay in seconds between characters (default is 0.3).volume
: (optional) The volume of the Morse code playback (default is 0.5).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_sounddevice
text: str = encode('Bonjour !', language='french')
play_sounddevice(text, volume=1.5)
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(dot='·')
Contact
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file morsecodepy-3.8.tar.gz
.
File metadata
- Download URL: morsecodepy-3.8.tar.gz
- Upload date:
- Size: 145.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2616220f6778eccb14f8a5f9cdf07ab6ae3425c2dd9d9d44c2dafe4e7f3bc3 |
|
MD5 | fdb711e6d0fdea90eb49d05d04b3ac84 |
|
BLAKE2b-256 | e1e98e4f41ff35f131042330397f0141f15ea57373cf374126b7e46363cdcd73 |
File details
Details for the file morsecodepy-3.8-py3-none-any.whl
.
File metadata
- Download URL: morsecodepy-3.8-py3-none-any.whl
- Upload date:
- Size: 145.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcf6bd0821ca3c6d9c5c220d1b2146c70be7a9adaa127c4bc3b4802100807d02 |
|
MD5 | 1b7fe317e0555f957e356d3c1f6b421d |
|
BLAKE2b-256 | 43278e322df4858651f6dc9222db4d939ff41e9c3c7ef83224a4fc659033fae9 |