Skip to main content

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

Project description

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

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

py_simple_morse_code-0.0.5.tar.gz (53.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_simple_morse_code-0.0.5-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file py_simple_morse_code-0.0.5.tar.gz.

File metadata

  • Download URL: py_simple_morse_code-0.0.5.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for py_simple_morse_code-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7b7450d19e7ce02607d467628cea6cdd38629732c21e89a00fc884094e484b51
MD5 6f4193c456d52344b5a27f28e16ed298
BLAKE2b-256 b7a36b7db92ba91a7161c8684f21c33f624050e460bc005a9a7e74552d447162

See more details on using hashes here.

File details

Details for the file py_simple_morse_code-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for py_simple_morse_code-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e85bef64be174a80cea249ee84420834ce755b8f06295550ac99b65fb5a6ac7d
MD5 29fad21b4176f29f3b6e272be76f23c6
BLAKE2b-256 d558590dee5d9fee033592d59b074bf12fbf811faeeb79667f5e45808e9dd9ca

See more details on using hashes here.

Supported by

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