Skip to main content

Morse audio decoder

This program is in solution to Wunderdog Wundernut vol. 11, whose instructions can be found in their GitHub.

The program reads wav audio file, and outputs decoded morse code in standard output.

Quickstart

Installation

Option 1 - pip

You can install this package from pip, with

pip install morse-audio-decoder

Option 2 - Local install from sources

Clone code repository from your local machine, install from there:

git clone https://github.com/mkouhia/morse-audio-decoder.git
cd morse-audio-decoder
poetry build
# take note of the build step output, install package from the dist folder
pip install dist/PRODUCED_PACKAGE.whl

Usage

To run the script installed with pip, perform

morse-audio-decoder WAVFILE

or alternatively,

python -m morse_audio_decoder WAVFILE

where WAVFILE is path to the audio file to be processed.

The program decodes audio morse code in the WAVFILE argument, and writes translation to standard output. See program help with command line flag -h:

$ morse-audio-decoder -h
usage: morse-audio-decoder [-h] WAVFILE

Read audio file in WAV format, extract the morse code and write translated text into standard output.

positional arguments:
WAVFILE     Input audio file

options:
-h, --help  show this help message and exit

Usage in Python

from morse_audio_decoder.morse import MorseCode

morse_code = MorseCode.from_wavfile("/path/to/file.wav")
out = morse_code.decode()
print(out)

Technical description

The program works in following steps

  1. Read in the WAV file.
  2. Extract analytic envelope from the signal by calculating moving RMS amplitude with Hann window of default 0.01 second width. This envelope signal is smooth and always greater than or equal to zero.
  3. Convert envelope to binary 0/1 signal by applying threshold, by default 0.5 * max(envelope)
  4. Calculate durations of continuous on/off samples
  5. Identify dash/dot characters and different breaks with K-Means clustering. The lengths of periods are compared, and then labeled automatically based on number of samples.
  6. Create dash/dot character array, which is then broken to pieces by character and word space indices
  7. Translate morse coded characters into plain text, print output

Exploratory data analysis and first program implementation is performed in this jupyter notebook. The notebook is not updated; actual implementation differs.

Restrictions

This decoder has been tested and developed with inputs that have

  • no noise
  • constant keying speed
  • constant tone pitch
  • single input channel.

If the decoder were to be extended to noisy inputs with major differences, at least following changes would be required

  • pitch detection in moving time
  • signal extraction with narrow bandpass filter, based on identified pitch
  • keying speed detection (characters/words per minute)
  • decoding in smaller time steps, taking into account speed changes.

The program is also not intended to identify single characters, as the precision will be lower with shorter inputs.

Development

Environment

Requirements:

Dependencies:

  • Numpy
  • Scikit-learn
  1. Install dependencies with poetry install
  2. Enter environment with poetry shell

Code quality and testing

All code is to be formatted with black:

black **/*.py

and code quality checked with pylint:

pylint **/*.py

Tests should be written in pytest, targeting maximum practical code coverage. Tests are run with:

pytest

and test coverage checked with

pytest --cov

Optionally, html test coverage reports can be produced with

pytest --cov morse_audio_decoder --cov-report html

Contributions

Contributions are welcome. Please place an issue or a pull request.

Release files for morse-audio-decoder 0.1.1

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

Source distribution (sdist)

Source distribution for morse-audio-decoder 0.1.1
File Size Uploaded
morse-audio-decoder-0.1.1.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for morse-audio-decoder 0.1.1
File Interpreter ABI Platform
morse_audio_decoder-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / morse-audio-decoder-0.1.1.tar.gz

Download URL morse-audio-decoder-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aa2eb41b747481584d59be12f7d0d0581d3c118d9005c39393f26e5fd61bf887
BLAKE2b-256 checksum
How to use checksums
97858665dbe81cf642c433a0c0d788132a4c5add2c0c239922962337b3d9fa38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.13.0-30-generic

Release files / morse_audio_decoder-0.1.1-py3-none-any.whl

Download URL morse_audio_decoder-0.1.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d14341efd78e3d013f4f1ce0dfe16ab3a939b70a0c9f3c094cdcbc386acc5b1
BLAKE2b-256 checksum
How to use checksums
cc3f0d44d3a21758a5ffe1fa17a32798b83eef1181e109c8c617f0fbc71b891a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.13.0-30-generic

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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