A python module for interacting with morse code with live decoding feature.
Project description
py_simple_morse_code_raspi 0.0.5
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
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
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 py_simple_morse_code_raspi-0.0.5.tar.gz
.
File metadata
- Download URL: py_simple_morse_code_raspi-0.0.5.tar.gz
- Upload date:
- Size: 53.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6601eec075554a7a1901ce783e963a25a44266736cbc04317563656c9dfa6100 |
|
MD5 | 70b4dab4c92f12f43418f6238de7fdf0 |
|
BLAKE2b-256 | 162f72c571de42fca60b3db3548d6395afe1ebc847f80fe69718e683cb0dc0b1 |
File details
Details for the file py_simple_morse_code_raspi-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: py_simple_morse_code_raspi-0.0.5-py3-none-any.whl
- Upload date:
- Size: 41.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 140425ac6d8b456e90ed28a964eb7a5e41cfd45346eab2311b835bcc38d4a970 |
|
MD5 | 24e5b688510783b6858ee7a2aba1923d |
|
BLAKE2b-256 | 1f9994a03a1d67ea64f0b70fde00d2d8b64ac03e41f62e5a8129b94d820251e3 |