Skip to main content

py_simple_morse_code 0.0.5

Morse Encoder

Morse Decoder

Live Decoder


About^

A python module for interacting with morse code with live decoding feature.

Live Decoder In Action: https://raw.githubusercontent.com/AndrewSpangler/py_simple_morse_code/main/docu/live_decoder.mp4

Installation^

Run `pip install py_simple_morse_code`

Requirements^

pyaudio

scipy

numpy

GUI Usage^

To launch the gui, install via pip and run python -m py_simple_morse_code

Module Usage^

from py_simple_morse_code import SignalProcessor, MorseCodeTranslator

signal_processor = SignalProcessor(mic_index=0, min_tone=800, max_tone=1200)
decoder = MorseCodeTranslator(words_per_minute=10)
last_content = ""
try:
    signal_processor.start_session()
    print("Begin processing")
    while True:
        decoder.update(signal_processor.process())
        if not decoder.parsed_content == last_content:
            last_content = decoder.parsed_content
            print(last_content)
except Exception as e:
    print("End processing")
    signal_processor.end_session()
    raise e

Classes^

SignalProcessor^

Non-blocking CW signal processor. The .process() method returns true if a CW tone was found in the signal.

class SignalProcessor(object):
	def __init__(self, mic_index: int = 0, min_tone: int = 600, max_tone: int = 1500, sample_size: int = 512, sample_rate: int = 32000, high_pass_frequency: int = 4, low_pass_frequency: int = 10000):
		...
	def end_session(self) -> None:
		"""Ends the audio stream. *Returns None*"""
	def process(self) -> bool:
		"""Process a chunk of the audio stream from the buffer. *Returns None*"""
	def start_session(self) -> None:
		"""Start the audio stream. *Returns None*"""

MorseCodeTranslator^

A low-level morse code translator. Inputs should be debounced / sanitized before being passed to the .update(state:bool) method. Tolerance only affects word-sep deadbeats to account for hesitation / early resumes between words.

class MorseCodeTranslator(object):
	def __init__(self, words_per_minute: int = 24, debounce_time: float = 0.01, tolerance: int = 0):
		...
	def update(self, state: bool) -> None:
		"""Call this whenever input state changes. Alternatively call this at a set frequency with the current state. *Returns None*"""

Functions^

encode_string_to_morse^

Encodes text to morse code dots and dashes. Returns a string

def encode_string_to_morse(in_str: str, short_char: str = '.', long_char: str = '-', sep_char: str = ' ', replace_on_unknown: str = '?', verbose: bool = True) -> str:
> 	...

encode_string_to_beats^

Converts a plaintext string to a beats list. Returns a list of bools

def encode_string_to_beats(in_str: str, verbose: bool = True) -> list:
> 	...

encode_string_to_waveform^

Encode a plaintext string to a waveform. Returns a float32 1-dimensional numpy array

def encode_string_to_waveform(in_str: str, tone: int = 1000, words_per_minute: int = 24, sample_rate: int = 32000, verbose: bool = True) -> numpy.ndarray:
> 	...

encode_morse_to_beats^

Converts dots and dashes to a beats list. Returns a list of bools

def encode_morse_to_beats(morse: str, verbose: bool = True) -> list:
> 	...

encode_morse_to_waveform^

Encode a morse string to a waveform. Returns a float32 1-dimensional numpy array

def encode_morse_to_waveform(morse: str, tone: int = 1000, words_per_minute: int = 24, sample_rate: int = 32000, verbose: bool = True) -> numpy.ndarray:
> 	...

encode_beats_to_waveform^

Encode a beats list into a waveform. Returns a float32 1-dimensional numpy array

def encode_beats_to_waveform(beats: list, tone: int = 1000, words_per_minute: int = 24, sample_rate: int = 32000, verbose: bool = True, volume: float = 0.75, deadbeats: int = 0) -> numpy.ndarray:
> 	...

decode_morse_to_string^

Decodes morse dots and dashes to plaintext. Returns a string

def decode_morse_to_string(morse: str, char_sep: str = ' ', word_sep: str = '  ', replace_on_unknown: bool = '?') -> str:
> 	...

make_morse_visual_from_beats^

Converts a beats list to a visual representation in string form using block chars (unicode char 2588). Returns a string

def make_morse_visual_from_beats(beats: list) -> str:
> 	...

play_morse^

Converts dots and dashes to a waveform and plays it on system speakers. Returns None

def play_morse(morse: str, tone: int = 1000, words_per_minute: int = 24, sample_rate: int = 32000, verbose: bool = True) -> None:
> 	...

play_string^

Converts plaintext to a waveform and play it on system speakers. Returns None

def play_string(in_str: str, tone: int = 1000, words_per_minute: int = 24, sample_rate: int = 32000, verbose: bool = True) -> None:
> 	...

play_waveform^

Plays a waveform. Return None

def play_waveform(waveform: bytes, format=1, sample_rate=32000) -> None:
> 	...

Changelog^

0.0.5^

Make module more widely compatible by removing newer syntax.

0.0.4^

Fix PyPi page links

0.0.3^

Add example usage and images to readme and clean up typehints

0.0.2^

Move main module to src/py_simple_morse_code/main.py

0.0.1^

Fix main module not being included in pip module.

0.0.0^

Create Project

Generated with py_simple_readme

Metadata

Release files for py-simple-morse-code 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-simple-morse-code 0.0.5
File Size Uploaded Provenance Actions
py_simple_morse_code-0.0.5.tar.gz 53.0 kB Without provenance Details for py_simple_morse_code-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-simple-morse-code 0.0.5
File Interpreter ABI Platform Actions
py_simple_morse_code-0.0.5-py3-none-any.whl Python 3 none any Details for py_simple_morse_code-0.0.5-py3-none-any.whl

Total release size: 94.2 kB

Release files / py_simple_morse_code-0.0.5.tar.gz

Download URL py_simple_morse_code-0.0.5.tar.gz
Size 53.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7b7450d19e7ce02607d467628cea6cdd38629732c21e89a00fc884094e484b51
BLAKE2b-256 checksum
How to use checksums
b7a36b7db92ba91a7161c8684f21c33f624050e460bc005a9a7e74552d447162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / py_simple_morse_code-0.0.5-py3-none-any.whl

Download URL py_simple_morse_code-0.0.5-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e85bef64be174a80cea249ee84420834ce755b8f06295550ac99b65fb5a6ac7d
BLAKE2b-256 checksum
How to use checksums
d558590dee5d9fee033592d59b074bf12fbf811faeeb79667f5e45808e9dd9ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Security for py-simple-morse-code 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page