Skip to main content

Decode morse code from input audio file

Project description

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.

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

morse-audio-decoder-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

morse_audio_decoder-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file morse-audio-decoder-0.1.1.tar.gz.

File metadata

  • Download URL: morse-audio-decoder-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.13.0-30-generic

File hashes

Hashes for morse-audio-decoder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aa2eb41b747481584d59be12f7d0d0581d3c118d9005c39393f26e5fd61bf887
MD5 70f36961cd299a4f51c7b4ea2f4c6a8c
BLAKE2b-256 97858665dbe81cf642c433a0c0d788132a4c5add2c0c239922962337b3d9fa38

See more details on using hashes here.

File details

Details for the file morse_audio_decoder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for morse_audio_decoder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d14341efd78e3d013f4f1ce0dfe16ab3a939b70a0c9f3c094cdcbc386acc5b1
MD5 fa13afc8e53f24fd7e2ae1b01a77a54c
BLAKE2b-256 cc3f0d44d3a21758a5ffe1fa17a32798b83eef1181e109c8c617f0fbc71b891a

See more details on using hashes here.

Supported by

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